By default when you create a user in Linux, users default home directory is created under /home. If you noticed on Ubuntu and Debian derivated distribution useradd command won't create a home directory by default.
Let's think of s situation where you have already created a user but the home directory is missing. In this tutorial, I will show you how to create a default home directory for an existing user in Linux.
Create default home directory for existing user
Here I am using Ubuntu 20.04 and going to create a user named ' bob' using useradd command:
$ sudo useradd bob
Useradd command has added an entry home directory in /etc/passwd file
$ grep bob /etc/passwd bob:x:1003:1003::/home/bob:/bin/sh $
If I try to login as the user using
su -, it shows that it's
logging in with Home=/. This means the user home directory is not created.
$ su - bob Password: No directory, logging in with HOME=/ $
In Linux, a user's default home directory is /home. To create a default home directory use
Make sure to run
mkhomedir_helper command as root or user with sudo access.
$ sudo mkhomedir_helper bob
The previous command creates a home directory named "/home/bob" and user settings files.
$ ls -al /home/bob total 20 drwxr-xr-x 2 bob bob 4096 Jun 1 02:26 . drwxr-xr-x 5 root root 4096 Jun 1 02:26 .. -rw-r--r-- 1 bob bob 220 Jun 1 02:26 .bash_logout -rw-r--r-- 1 bob bob 3771 Jun 1 02:26 .bashrc -rw-r--r-- 1 bob bob 807 Jun 1 02:26 .profile
For a graphical environment (such as GNOME or XFCE ), if you are missing subdirectories in the home directory, the user needs to log out and log in back.
When the user login the first time all subdirectories such as Pictures, Documents, Videos, and Downloads folders can be created in the home directory.
Another method is to delete the user and create a new user using
The following command creates a home folder (-m) and set the specified home directory (-d) as the value for the new user's login:
$ sudo useradd -m -d /home/bob01 bob01
To conclude, If you are a Ubuntu fan you should be now using adduser command, it's recommended by Debian. If you have an existing user, now you should be able to add default directory.
Thanks for reading and please drop your suggestions on the below comment section.