Creating a home directory for a user - linux

Hi I added a user using useradd command so that he have no home directory:
useradd -M -u 1110 brinst
Then I wanted too add a home directory for the same user using usermod but that didn't work out:
usermod -m -d /home/lagha brinst
usermod: no changes
How can I create a home directory with all it's folders and hidden files for this user when he doesn't have an old one? - that seems to be easy but somehow it's not working.

mkdir /home/brinst
usermod -d /home/brinst brinst
More cleaner way:
mkhomedir_helper brinst

create user with command like
sudo useradd my-new-user -m -d /home/my-new-user

Related

Not able to create a directory using sudo -u username mkdir /var/log/test

I am unable to create a directory using sudo priveleges from root user and If I login to user , I can create an directory under /root using sudo. Also I have added to allow all commands in /etc/sudoers file and the details are below:
[root#linux home]# cat /etc/sudoers | grep tes
test ALL= NOPASSWD: ALL
Error
[root#linux home]# sudo -u test mkdir /var/log/test3
mkdir: cannot create directory ‘/var/log/test3’: Permission denied
Any Ideas ?
Thanks
By running 'sudo -u test', you're giving yourself lower privileges than the roor user because you're running the command as the user 'test', not 'root'. From the root user, you can just run:
mkdir /var/log/test3
Read man sudo for more info.
Or:
Run visudo and uncomment the wheel group, then add the user test to the wheel group.
If you don't mind me asking, why do you need to create a directory as a certain user from the root user? Especially since the directory you're making will not be user specific?
Also, in the sudoers file , you should what added test ALL=(ALL) NOPASSWD: ALL, not test ALL= NOPASSWD: ALL

Linux Ubuntu and Symfony cache directory

After composer install symfony cache:clear, I lose permission in app/cache directory and I must execute chmod 777 command again.
This should be connected with ownership of that directory or?
The problem here is, that executing composer with your current user lets Symfony create cache-files with your user and not the www-data user (or whatever user for your webserver is configured).
Try running composer install / bin/console with your webserver's user, eg. sudo -u www-data bin/console cache:clear / sudo -u www-data composer install.
Regards
tried to look on the side of ACL ubuntu
HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache
In setfacl command add more "-m" option with users needed
You can found more exemple in documentation
http://symfony.com/doc/current/book/installation.html#checking-symfony-application-configuration-and-setup

Incorrect $HOME env variable for a newly created user

On my Ubuntu machine, I logged in as "olduser" and created "newuser" using the following command:
adduser --system --home /usr/share/newuser --no-create-home --ingroup newgroup --disabled-password --shell /bin/false newuser
This adds a new line:
newuser:x:104:1001::/usr/share/newuser:/bin/false
to my /etc/passwd file. But when I log into the machine as 'newuser', my home directory is set as /home/olduser.
echo $HOME
gives
/home/olduser
The same command mentioned above works as expected on a Debian machine but not on the Ubuntu machine.
Why could this be happening?
Edit
I tried changing the home directory using the command
usermod -m -d /usr/share/newuser newuser
This also didn't help.
Instead of changing the dir in /etc/passwd try usermod this way:
usermod -m -d /newhome/username username
Since you've already changed this file try logging out and in again.

linux new user with sftp to specific folder

Hi I have ssh connection to my server wit root account. I want to create user named pizza4yu and give access with winscp to only this location /home/pi/apache-tomcat-7.0.35 How can I do that ?
chsh -s /bin/bash pizza4yu
usermod -d /home/pi/apache-tomcat pizza4yu
chown -R pizza4yu:pizza4yu /home/pi/apache-tomcat
You can also use chroot: http://chrootssh.sourceforge.net/
Set the users home folder to that path so.
Usermod -d /home/pi/apache-tomcat pizza4yu
All in lowercase
Then chown -R pizza4yu /new/path or add the new user to existing group of that folder

Adding FTP user via bash script issue

I have a .sh file (lets say adduser.sh) that is executed via a cronjob that contains the commands to create an FTP user.
The adduser.sh file looks like so...
#!/bin/bash
mkdir /var/www/vhosts/domain/path;
useradd -d /var/www/vhosts/domain/path -ou <uid> -g <group> -s /bin/false <username>;
echo <password> | passwd <username> --stdin;
Now here is my problem. If I run it directly through SSH using...
sh adduser.sh
...no problems and it works as intended.
But if I let the cronjob run it the directory is created but the user is not added.
What gives?
As it stands, there is an alternative to useradd known as adduser. In Debian or Ubuntu, adduser is a perl script and performs sequential functions like create the user using adduser, assign it to a group, create home directory etc.
As per adduser man page-
adduser and addgroup are friendlier front ends to the low level tools
like useradd, groupadd and usermod programs, by default choosing
Debian policy conformant UID and GID values, creating a home directory
with skeletal configuration, running a custom script, and other
features.
In Fedora, RedHat, and CentOS, adduser is just a symbolic link to useradd.
[root#hobbit ~]# which /usr/sbin/adduser
lrwxrwxrwx 1 root root 7 2012-09-20 20:20 /usr/sbin/adduser -> useradd
If you are on any on the above OS then you can try adduser redirect 2> to a add_user.log file and check the file to see if something goes wrong.
I have resolved this simply adding /usr/bin/ to the useradd function.
#!/bin/bash
mkdir /var/www/vhosts/domain/path;
/usr/bin/useradd -d /var/www/vhosts/domain/path -ou <uid> -g <group> -s /bin/false <username>;
echo <password> | passwd <username> --stdin;
Thanks everyone for helping me get on the right track. Hope this helps someone out there.

Resources