How to Create a Home Directory for Existing Users in Linux?

The “Home” directory refers to the default “login” directory of the specified user in the system. It is created automatically during the creation of any user. While using Linux, you might have encountered an error “cannot change directory to /home/user: No such file or directory”, which represents that the user does not have the home directory. In such a case, the home directory needs to be recreated for that user. 

Keeping the importance in view, this post will list the possible steps to create a Home directory for existing users in Linux. 

How to Create a Home Directory of Existing Users in Linux?

Follow the following necessary steps to create the “home” directory In Linux.

Step 1: Check the Home Directory (Existing User)

Execute the “su(switch user)” with the “sudo” privileges to access the existing user “anna” home directory. At this point, the logged-in user is “itslinuxfoss”:

$ sudo su - anna

The output shows that there is no “home/anna” directory.

Step 2: Create Home Directory

Run the mkhomedir_helper command by specifying the “anna” user in the following way:

$ sudo mkhomedir_helper anna

The above command was executed successfully.

Step 3: Verify the Home Directory

For verification again, use the “su” command to switch the user to “anna” and then confirm the “home/anna” directory by using the “ls” command:

$ sudo su -anna

The “itslinuxfoss” user has been switched to the “anna” home directory.

Execute the “ls(list)” command with the combination of “a(all)” and “l(list)” flags to list down the “home/anna” directory content:

$ ls -al /home/anna

In the terminal, the above command has displayed the content of the “home” directory of existing user “anna”.

Conclusion

In Linux and its distributions, the user can easily and quickly create the home directory for an existing user with the help of the “mkdirhome_helper” command. This command is pre-installed in all Linux distributions. 

This guide has enlisted the complete procedure to create an existing user home directory in Linux.