How to Add and Delete Users on Red Hat Enterprise Linux 9

How to Add and Delete Users on Red Hat Enterprise Linux 9

In Linux system administration, managing users and groups is one of the basic tasks. Therefore, it is important to know how to manage users and groups on Linux.

In this tutorial, we are exploring the methods to add and delete users on Red Hat Enterprise Linux 9.

Prerequisites

  • Red Hat Enterprise Linux 9 instance
  • Root account or an account with sudo privileges

Adding Users on Red Hat Enterprise Linux 9

You can add a new user with the help of ‘adduser’ command. Suppose you want to add a user ‘tony’. The command is as follows.

sudo adduser tony

When a command is executed, it doesn’t produce any output. It creates a user and his/her home directory.

You can confirm with the help of the following command.

cat /etc/passwd | grep tony

user-add-confirm

Next, you need to assign a password to this new user so that he/she can login. The command is as follows:

sudo passwd tony

Enter the password twice for confirmation when you are prompted. Submit a strong password that includes special characters, numbers, upper and lower case letters.

Now, your new user can log in to the system.

Giving Sudo Privileges to New User on Red Hat Enterprise Linux 9

When a user is given sudo privileges, he/she can execute commands with administrative privileges just by adding sudo with the actual command. The user will be prompted to submit his/her password.

‘Wheel’ is a default sudoer group in Red Hat Enterprise Linux 9 and the previous version. Any user added to this group will have sudo privileges.

Let’s try adding user ‘tony’ to this ‘wheel’ group as follows.

sudo usermod -aG wheel tony

You can verify this operation with the ‘lid’ command as follows. ‘lid’ helps show which groups a user belongs to. In this case, we will reverse the operation with -g option and see which members belong to ‘wheel’ group.

sudo lid -g wheel

As you can see from the output of the command, tony is a member of ‘wheel’ group.

Removing Users on Red Hat Enterprise Linux 9

If you want to delete a user tony without deleting the home directory(files), the command is as follows.

sudo userdel tony

Use the -r switch if you want to delete the user along with his home directory(files).

sudo userdel -r tony

Conclusion

Thank you for reading. Please leave feedback to help improve this article. Keep visiting Linux World.