The sudo
command provides a mechanism to grant administrator privileges to all other users on the server. These admin privileges are usually available only to the root user. This guide will help you how to create a new user with sudo
access on Rocky Linux 8, without having to modify your server’s /etc/sudoers
file.
Note: If you want to configure sudo
for an existing user, please go to step 3.
Step 1 — Logging Into Your Server
SSH in to your server as the root user:
- ssh root@your_server_ip_address
Use your server’s IP address or hostname in place of your_server_ip_address above.
Step 2 — Add a New User
Use the adduser
command to add a new user to your system:
Be sure to replace user123 with the username you’d like to create.
Use the passwd
command to update the new user’s password:
Changing password for user user123. New password: Retype new password: passwd: all authentication tokens updated successfully.
Step 3 — Adding the User to the wheel Group
Use the usermod
command to add the user to the wheel group:
Step 4 — Test sudo
Access
To test that the new sudo
permissions are working, first use the su
command to switch from the root user to the new user account:
As the new user, verify that you can use sudo
by prepending sudo
to the command that you want to run with superuser privileges:
The first time you use sudo
in a session, you will be prompted for the password of that user’s account. Enter the password to proceed:
[sudo] password for user123:
Note: This is not asking for the root password! Enter the password of the sudo-enabled user, not the root password.
If your user is in the proper group and you entered the password correctly, the command that you used with sudo
will run with root privileges.