Question
Linux adduser command needs --home Dir option
New account with “adduser user”
After ssh into root@ipAddress, I tried to create a new user account as “Initial Server Setup with Ubuntu 14.04” suggested. The new account was created, but with some anomalies:
- No “user@hostname” in the shell prompt
- No /home/user directory
- No /bin/bash shown in /etc/passwd
- Unable to “deluser user”
For example,
after “adduser leon” and login as leon:
$ id
uid=1000(leon) gid=1000(leon) groups=1000(leon),27(sudo)
$ grep -i leon /etc/passwd
leon:x:1000:1000::/home/leon:
$ su root
root@Leon-Ubuntu:/# deluser leon
Removing user leon' ...
leon’ has no more members.
Warning: group
userdel: user leon is currently used by process 2060
/usr/sbin/deluser: `/usr/sbin/userdel leon’ returned error code 8. Exiting.
Then I tried the “–home Dir” option
and it works well.
root@Leon-Ubuntu:/# adduser –home /home/leon2 leon2
root@Leon-Ubuntu:/# grep -i leon /etc/passwd
leon:x:1000:1000::/home/leon:
leon2:x:1001:1001:,,,:/home/leon2:/bin/bash
root@Leon-Ubuntu:/# ls /home/
leon2
root@Leon-Ubuntu:/# deluser leon2
Removing user leon2' ...
leon2’ has no more members.
Warning: group
Done.
Is there an explanation about this?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×
I tried “adduser username” again and it worked this time. But it has some inconsistency again in the following scenario. First time I issued it in a user mode, it said “only root may add…” and yet the user was silently created. Later time, it turned correct by not creating the user. It seems that the first time you invoke adduser, it has a glitch and became ok subsequently.
leon@Leon-Ubuntu:/root$ adduser leon5
adduser: Only root may add a user or group to the system.
leon@Leon-Ubuntu:/root$ ls /home/
leon2 leon3 leon4 leon5
leon@Leon-Ubuntu:/root$ grep -i leon /etc/passwd
leon:x:1000:1000::/home/leon:
leon5:x:1003:1003:,,,:/home/leon5:/bin/bash
leon@Leon-Ubuntu:/root$ su leon5
Password: // It didn’t go through Password setup step
leon5@Leon-Ubuntu:/root$ ls // ls doesn’t work
ls: cannot open directory ’.’: Permission denied
leon5@Leon-Ubuntu:/root$ pwd // pwd works though
/root
Found this link that says alternatively we could invoke “useradd”, which is more suitable for scripting and is a low level call that is supported in all Linux distros. But you have do all the lifting: useradd can create home directory with -m, set password with -p, create skeleton files with -k, and add user to group(s) with -G.