How to Create Home Directory for Existing User in Ubuntu

You need a home directory where you can keep your files, folders, documents, and all other stuff. In the Ubuntu distribution of Linux, no home directory is created while adding a new user. This can be a problem while using it. In this article, I will show you how to create a home directory for an existing user in Ubuntu.

Steps to Create a Home Directory for an Existing User in Ubuntu

In the following example, I will create a new user named “abir”. Then, I will make a home directory for the user. I have illustrated the full process in the following 4 steps:

Step 01: Create a New User

You can create a new user from the terminal using the useradd command. Go through the below steps to see how it works:

  1. Open the Ubuntu Terminal by pressing CTRL+ALT+T.
  2. Insert the following command to create a user:
    useradd abir
    EXPLANATION
    • useradd: Adds a new user
    • abir: Creates a new user named abir.
    Usedadd command not working
  3. You have to be a root user to execute the useradd command. You can easily do this by using this command:
    sudo useradd abir

    Here the sudo command grants administrative privileges.

  4. Press the ENTER key after providing the password.
    Create user by using sudo
  5. Now, set a password for the newly created user by typing the following command:
    sudo passwd abir

    Here, You need to type the password of the root user. Then you have to type the new user’s password and retype the password.
    set password for new user in ubuntu

  6. Finally, you can check whether the user has been created or not by typing the following command:
    getent passwd | grep abir
    EXPLANATION
    • getent: Looks into the administrative database that is given as its argument.
    • passwd: Contains user information.
    • Pipe (|): Redirects the standard output.
    • grep: Looks for a specific pattern given to it as an argument.
    verifying new user to create home directory in ubuntu

You can see in the above picture that a new user named abir has been created.

Step 02: Log into the New User

To log into the new user account you can just type the below command in your Ubuntu Terminal:

su - abir

After pressing the ENTER button, you will see that your command prompt and terminal will change as shown in the below picture.switch user to create home directory in ubuntuYou can see a warning message on the screen. It says no home directory is created for the new account.



Step 03: Make a Home Directory for the User

To make a home directory for the user you just need to type the following command:

sudo mkhomedir_helper abir

The mkhomedir_helper command creates a user’s home directory and populates it with default configuration files.

Now, type your password and press the ENTER button.Create Home Directory for Existing User in Ubuntu Your home directory will be created after giving the password.

Read More: Create User Without Home Directory in Ubuntu in Just 3 Steps

Step 04: List Files in the Home Directory

You can check whether your home directory is created or not. You just type the below command in your Ubuntu Terminal:

ls -al /home/abir

After pressing the ENTER button, you will see that a list of all the files is displayed on the screen. Your home directory is created.List all files in Home directory



Conclusion

After completing this article you will be able to create a home directory for the existing user in your Ubuntu distribution. This will help you to organize your files, folders, documents, and all the necessary things that you need to keep.

People Also Ask

Can multiple users have the same home directory in Linux?

No, multiple users cannot have the same home directory in Linux. Each user must have a unique home directory, which serves as their personal space for storing files, configuration settings, and other user-specific data. This ensures that each user has their own isolated environment and personalization.

Sharing a home directory among multiple users would lead to conflicts and security issues, as users might unintentionally access or modify each other’s data.

How to add a user to my home directory?

To add a user to your home directory, use sudo useradd username to create a new user. Set a password with sudo passwd username
Replace “username” with the desired username and “groupname” with the desired group.

How do I create a directory in my home directory?

To create a directory in your home directory, use the mkdir ~/<Directory_Name> command in the terminal. Replace “Directory_Name” with the desired name for your new directory. This command uses the “mkdir” command to make a new directory, and the tilde (~) symbol represents your home directory.

What permission should the home directory have?

The home directory should typically have 700 (dwrxr-xr-x.) permissions, ensuring maximum security by granting read, write, and execute permissions exclusively to the owner, while restricting access for others.

Related Articles

5/5 - (2 votes)
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
icon linux
Borhan Uddin

Hello, I am Borhan Uddin, a resident of Dhaka, Bangladesh. I have completed my undergraduate degree in Electrical and Electronic Engineering (EEE) from Chittagong University of Engineering and Technology (CUET). I love to spend my leisure by playing and watching various movies & dramas. Currently, I am working as a Linux Content Developer Executive here. I would like to learn more about Linux every day of the week and would be keen to share it with you rapidly. Read Full Bio

Leave a Comment