Looking for a way to create a home directory for the existing user? Well, here's a quick guide for you.
But before that, let's have a look at why there was no home directory for the user in the first place.
Reason why home directory was not created
So if you used the
useradd command to add the new user in Linux, it won't add the home directory by default.
And if you insist on using the
useradd command to create the new user, you just have to append the
-m option and it will create a home directory by default.
Create the home directory for existing user
When the existing user does not have a home directory and tries login with the
su - option, it will get you the following error:
Which clearly states that there is no home directory.
The first step is to log out from the user that does not have the home directory using the given command:
Now, all you need to do is append the
mkhomedir_helper and the username with the
sudo mkhomedir_helper username
My user is named as
Abhiman so my command would look like this:
sudo mkhomedir_helper Abhiman
And it will create a home directory for the user. For me, it will be named as /home/Abhiman:
ls -al /home/username
And if you are using desktop environments such as GNOME, KDE, etc. you will need to reboot your system to have sub-directories such as Downloads, Documents, and so on.
Bonus: Creating new users with the home directory
I prefer the adduser command for the reason that it allows the proper creation of a new user in Linux.
The regular useradd command is also capable of creating a new user with the home directory in this fashion:
sudo useradd -m new_user
This was a quick tutorial on how you can create a home directory for the existing user.
I won't recommend you to go with recreating the user (shown as a bonus tip) unless the user is recently made and you got to know that there is no home directory.
I hope you will find this helpful and if you have any queries, let me know in the comments.
Join the conversation