How to Create a Sudo User on CentOS
Sudo is a program that runs on Unix-like computer operating systems that enables users to execute programs under the privileges provided by another user, usually the superuser. Sudo refers to either “substitute user do” or “super user do” – either of which allows you to temporarily elevate your user account to have root privileges. This is not the same as “su”, which has a more permanent effect.
Our goal here is to walk you through setting up a sudo user on Debian,
Step 1: Configure VPSie cloud server
- Sign in to your system or register a newly created one by logging in to your VPSie account.
- Connect by SSH using the credentials we emailed you.
- Once you have logged into your CenOS instances and update your system.
Step 2: Set Up a New User Account
Use the adduser command to create a new user account. A user named “testuser” will be created here.
adduser testuser
Step 3: Set up the Sudo Group for the User and test it
Include the new user in the sudo group,
# passwd testuser
Changing password for user testuser. New password: Retype new password: passwd: all authentication tokens updated successfully.
Step 4: Add the User to the Wheel Group and test it
usermod -aG wheel testuser
Edit Sudoers File Check the sudoers file with visudo.
visudo
It’s now time to test,
su - testuser
That’s all for now, I hope you’ve found this informational
A sudo user is a regular user account that has been granted permission to use the sudo command to run commands with elevated privileges.
Creating a sudo user on CentOS is important for security reasons. By default, the root account has unrestricted access to the system, which makes it a target for attackers. By creating a sudo user, you can limit the risk of unauthorized access to the system.
You can create a sudo user on CentOS by following these steps:
Log in to the CentOS server as the root user.
Create a new user account:
useradd -m username
Replace “username” with the name of the user you want to create.
Set a password for the new user:
passwd username
Replace “username” with the name of the user you just created.
Add the user to the sudo group:
usermod -aG wheel username
This will grant the user permission to run commands with elevated privileges using the sudo command.
Test the sudo user: Switch to the newly created user account using the following command:
su - username
Then, test the sudo user by running a command with elevated privileges, such as:
sqlsudo yum update
If the command runs without any errors, then the sudo user has been set up correctly.
You can remove a sudo user by following these steps:
Log in to the CentOS server as the root user.
Remove the user from the sudo group:
gpasswd -d username wheel
Replace “username” with the name of the user you want to remove.
Delete the user account:
userdel -r username
Replace “username” with the name of the user you want to delete.
Yes, you can create multiple sudo users on CentOS by adding them to the “wheel” group using the “usermod” command.