Why is the home directory not created when I create a new user?

Finally I found how to do this myself:

   useradd -m -d /home/testuser/ -s /bin/bash -G sudo testuser

-m creates the home directory if it does not exist.
-d overrides the default home directory location. -s sets the login shell for the user.
-G expects a comma-separated list of groups that the user should belong to.

See man useradd for details.


The useradd program has been deprecated in favor of adduser. From man useradd:

useradd is a low level utility for adding users. On Debian,
administrators should usually use adduser(8) instead
.

adduser is a friendlier frontend to useradd and will do things like create user directories by default. When you run it with only a username as an argument, you will be prompted to provide additional information such as the password:

$ sudo adduser testuser
Adding user `testuser' ...
Adding new group `testuser' (1002) ...
Adding new user `testuser' (1002) with group `testuser' ...
Creating home directory `/home/testuser' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for testuser
Enter the new value, or press ENTER for the default
    Full Name []: 
    Room Number []: 
    Work Phone []: 
    Home Phone []: 
    Other []: 
Is the information correct? [Y/n] 

In general, you should always use adduser instead of useradd since this will also set up the required groups automatically. As explained in man adduser:

   adduser  and  addgroup  add users and groups to the system according to
   command    line    options    and    configuration    information    in
   /etc/adduser.conf.   They  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  fea‐
   tures. 

useradd -m LOGIN

creates the user's home directory

Tags:

Users

Useradd