Introduction
A non-root sudo user is a regular user account with administrative privileges. You can use it to perform system administration tasks without using the root account. This practice enhances security by limiting the use of the root account, reducing the risk of accidental or malicious system changes. Non-root sudo users also allow you to delegate specific administrative tasks to other users while maintaining control over the system.
This guide shows you how to create a non-root sudo user on a Rocky Linux 9.
Prerequisites
Before you begin, ensure you've:
- A Rocky Linux 9 server. We recommend a Digital Ocean VPS server.
- A user account with sudo privileges.
- An internet connection.
Creating a Non-Root Sudo User
In this section, you will create a new user named smith
and grant sudo privileges.
-
Create a new user.
CONSOLE$ sudo adduser smith
This command creates a new user account named smith.
-
Set a password for the new user.
CONSOLE$ sudo passwd smith
You will be prompted to enter and confirm a password for the new user.
-
Add the new user to the sudo group.
CONSOLE$ sudo usermod -aG wheel smith
This command grants the new user sudo privileges by adding them to the wheel group.
Verify the New Sudo User
In this section, you will verify that the new user has sudo privileges.
-
Switch to the new user account and enter a password when prompted.
CONSOLE$ su - smith
This command switches to the new user account.
-
Run a command with sudo privileges.
CONSOLE$ sudo whoami
You will be prompted to enter the password for the new user. If the new user has sudo privileges, the command will return the following response.
root
Conclusion
You have created a non-root sudo user on your Rocky Linux 9 server. This guide covered creating a new user, setting a password, and granting sudo privileges. You also verified that the new user has sudo privileges. Using non-root sudo users enhances security and allows you to delegate administrative tasks without compromising the root account. You can now use the new user account to perform system administration tasks securely.