The command sudo (short for Super-user do) is a program designed to allow a normal user (not root) to execute commands with unlimited privileges, which only the root user (Super Administrator) can do.
You can use this user account to run administrative commands without needing to log in to your PC or RockyLinux/CentOS server as the root user.
Creating User Sudo on Rocky Linux
By default, on Rocky Linux and CentOS, users in groups
wheel will be granted sudo access. If you want to configure sudo for an existing user, just add your user to the group
wheel, as shown in step 4.
Follow the steps below to create a sudo user on your Rocky Linux and CentOS server:
1. Log in to the server with SSH
Start by logging into your Rocky Linux or CentOS server as the root user.
ssh root@server _ip_address
2. Create a new user account on Rocky Linux
Create a new user account using the useradd command.
linuxstoney with the username you want to create.
3. Set the user password
passwd to set a password for the new user.
You will be asked to confirm the password. Make sure to use a strong password.
Changing password for user linuxstoney. New password: Retype new password: passwd: all authentication tokens updated successfully.
4. Add New User to sudo Group on Rocky Linux
By default, on Rocky Linux or CentOS systems, group members
wheel granted sudo access. To add a new user (or old user) to a group,
wheel type command:
usermod -aG wheel username
How to use sudo on Rocky Linux or CentOS
Switch to newly created user:
su - username
To use sudo, simply start the command with
For example, to view a directory’s table of contents
/root, then use the command:
sudo ls -l /root
If this is your first time using sudo, then you will see the following banner message and you will be asked to enter the password for the user account.
We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. [sudo] password for username:
You have successfully created a sudo user on your Rocky Linux and CentOS system. You can now use this user to perform administrative tasks on servers that require super administrator privileges and have unlimited powers.