Rocky Linux

How to Create the Home Directory for a User on Rocky Linux 9

Linux is known as a multi-user operating system because more than one user can work on a single OS simultaneously. Sudo is an acronym for super-user do which is used in Linux to perform unlimited administrative tasks. Apart from these sudo users, some regular users are helpful in many ways. There are many purposes in Linux to have different home directories and some of which are as follows:

    • Users individually customize their desktop environment, preferences, settings, etc.
    • Separate users set their rights and permissions for privacy and security purposes.
    • Decrease the risk of misuse of critical functions.
    • System resources such as CPU usage, memory, storage, etc. are allocated efficiently.

However, the system administrators sometimes get confused while assigning a new home directory to a user. If you want to know how to create the home directory for a user on Linux, this tutorial is the best resource for you. Here, we will describe the commands to create a home directory for a user in Rocky Linux 9.

How to Create the Home Directory for a User on Rocky Linux 9

In this section, we will create a new home directory for new and existing users. For this, we use the “useradd” command. This command adds a directory in the /etc/passwd file.

Create a Home Directory for a New User

Step 1: Login as Root

Instead of logging in as a regular user, log in as a root user:

sudo su -

 

Step 2: Create a Home Directory

After successfully logging in as a root user, you can create a new home directory through the “useradd” command:

useradd <new_directory name>

 
For example, let’s create a new home directory named “linuxhint” with the same username.

useradd linuxhint

 
Step 3: Verify the Created Home Directory

You can check whether the home directory is created from the default passwd directory.

getent passwd linuxhint

 

Once you create the home directory, the system automatically creates a group with the same GID. You can use the following command to check it:

getent group linuxhint

 

Step 4: Add a Password for the Home Directory

Use the following command to add the password to a newly created directory:

openssl passwd <password>

 

Bonus Tip: If you want to change the password of the directory, use the following command:

passwd <directory_name>

 

Create a Home Directory for an Existing User

Creating a home directory for an existing user is easier than creating a new one. In this example, you just have to run the following simple command which is something like this:

sudo useradd <directory_name>

 
Run the following “grep” command to verify whether the directory is created or not:

grep <directory_name> /etc/passwd

 

For verification, you can use the following command as well:

sudo ls -la /home/<directory_name>

 

You can customize your directory using the various options. To explore the arguments included in the “useradd” command, run the following command in the terminal:

useradd -h

 

Conclusion

Creating a new home directory in Linux enhances security, optimizes resource allocation, facilitates a multi-user environment, allows customization, separates privileges, and many more.

Creating and assigning specific home directories is beneficial in maintaining the system’s integrity. You can use the “useradd” command to create a home directory for both new and existing users.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.