1

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
Password:
No directory, logging in with HOME=/
test@ubuntu1604:/$ ls /home/test
ls: cannot access '/home/test': No such file or directory
mahmood
  • 1,875
  • Read this: https://askubuntu.com/questions/345974/what-is-the-difference-between-adduser-and-useradd .. useradd don't create the home directory. – Soren A Jun 21 '19 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 '19 at 10:34

1 Answers1

3
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.

nobody
  • 5,437