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.
In this guide, we will show you how to create a new user on a Rocky Linux, CentOS and AlmaLinux system and give it sudo access to regular users.
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.
useradd linuxstoney
Change linuxstoney
with the username you want to create.
3. Set the user password
Use commands passwd
to set a password for the new user.
passwd linuxstoney
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 sudo
and spaces.
sudo [COMMAND]
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:
Conclusion
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.
Some Rocky Linux Related Tutorials :
How to Install Rocky Linux 8 Step-By-Step Guide with Screenshots
How to Add EPEL Repository on Rocky Linux, AlmaLinux and CentOS
Leave a Reply