Although I have explicitly specified a home directory for a newly added user, after the login, there is no home for that user.

mahmood@ubuntu1604:~$ sudo useradd test -d /home/test -s /bin/bash
mahmood@ubuntu1604:~$ sudo passwd test
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
mahmood@ubuntu1604:~$ su - test
No directory, logging in with HOME=/
test@ubuntu1604:/$ ls /home/test
ls: cannot access '/home/test': No such file or directory
  • Read this: askubuntu.com/questions/345974/… .. useradd don't create the home directory. – Soren A Jun 21 at 10:34
  • 1
    Does /home/test already exist? if not, the -d option is not sufficient - you also need -m or --create-home – steeldriver Jun 21 at 10:34
sudo useradd test -m -d /home/test -s /bin/bash

According to the manpage

-m, --create-home Create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined with the -k option) will be copied to the home directory.

option -d says take the existing /home/test.

But it is better to use adduser as Soren A linkt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.