
The sudo
command designed for granting administrator privileges to normal users. This tutorial will show you the simple and easy way to create a new user on CentOS and make it sudo user account. You can use this user account to execute administrative commands without a need to logging as a root user in to your CentOS server.
Creating Sudo User On CentOS
Follow the steps below to create a sudo user on your CentOS server. You can skip user creation steps if you wants to give sudo access to existing user.
At First, Log in to your CentOS server as the root user.
ssh root@server_ip_address
Next, create a new user account using adduser command. Be sure to replace demouser
with the user name that you want to create.
adduser demouser
Use the passwd
command to set a password for the new user.
passwd demouser
It will prompt to confirm new password. Make sure you use a strong password. Use a combination of alphabets, upper case letter, special character and number as a password.
Output:
Changing password for user demouser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
By default on CentOS system, members of the wheel
group are granted with sudo access. Now, user is ready to add to wheel group to grant sudo access.
usermod -aG wheel demouser
Verify the sudo access
Login using new created user or you can switch to the new created user by type :
su - demouser
Use the sudo command to run the whoami command:
sudo whoami
If new user account have sudo access then output of given command will be root as below :
Now you can use sudo by just type sudo
before any command and give space :
sudo ls -la /root
Conclusion
Finally, You have learned how to create a user with sudo privileges. You can now log in to your CentOS server with this user account and use sudo to run administrative commands.
Your valuable suggestions are welcome. Feel free to leave a comment below.
Leave a Reply