How to Manage Users and Groups in RHEL

Red Hat Enterprise Linux (RHEL) is a popular operating system used by many businesses and organizations around the world. One of the key aspects of managing a RHEL system is managing users and groups. Users and groups allow system administrators to control access to resources and ensure that only authorized individuals have access to certain files and directories. In this article, we will discuss how to manage users and groups in RHEL.

Creating Users
To create a new user in RHEL, you can use the useradd command. This command allows you to specify various options such as the user’s username, full name, primary group, and home directory. For example, to create a new user named "johndoe" with the full name "John Doe" and the home directory "/home/johndoe", you can use the following command:

sudo useradd -c "John Doe" -m -d /home/johndoe johndoe

This command will create a new user with the specified options. You can then set a password for the user using the passwd command:

sudo passwd johndoe

Managing Users
Once you have created a user, you can manage their account using various commands. For example, to change a user’s password, you can use the passwd command:

sudo passwd johndoe

To change a user’s shell, you can use the chsh command:

sudo chsh -s /bin/bash johndoe

To delete a user, you can use the userdel command:

sudo userdel -r johndoe

Adding Users to Groups
Groups allow you to organize users and control access to resources based on group membership. To add a user to a group, you can use the usermod command:

sudo usermod -aG groupname johndoe

This command will add the user "johndoe" to the group "groupname". You can also use the groups command to display a list of groups that a user is a member of:

groups johndoe

Managing Groups
To create a new group in RHEL, you can use the groupadd command:

sudo groupadd groupname

This command will create a new group with the specified name. You can then add users to the group using the usermod command as described above.

To delete a group, you can use the groupdel command:

sudo groupdel groupname

This will remove the group from the system.

Conclusion
Managing users and groups in RHEL is an essential task for system administrators. By following the steps outlined in this article, you can create, modify, and delete users and groups as needed to control access to resources and ensure the security of your RHEL system.

Tags: 492492492