Linux adduser command needs --home Dir option

Posted April 11, 2018 5.1k views
Linux CommandsUbuntu 16.04

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:

  1. No “user@hostname” in the shell prompt
  2. No /home/user directory
  3. No /bin/bash shown in /etc/passwd
  4. 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
$ su root
root@Leon-Ubuntu:/# deluser leon
Removing user leon' ...
Warning: group
leon’ has no more members.
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
root@Leon-Ubuntu:/# ls /home/
root@Leon-Ubuntu:/# deluser leon2
Removing user leon2' ...
Warning: group
leon2’ has no more members.

Is there an explanation about this?

1 comment
  • 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@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

    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.

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.

Submit an Answer
1 answer

This is odd and I cannot say that I have encountered this on Ubuntu 16.04 myself but I was able to find some information indicating that others have experienced this issue with the default adduser command in Ubuntu 16.04. It seems the issue lies with the command reading and using the defaults specified for it.

You can find some suggestions and more information here.