The sudo command gives a mechanism for granting administrator privileges, ordinarily only available to the root user, to normal users.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Sudo queries.
In this context, we shall look into how 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.
How to Create Sudo User On CentOS ?
With the steps provided below, a CentOS administrator can create a sudo user on your CentOS server. You can skip user creation steps if you wants to give sudo access to existing user.
1. To begin, Log in to your CentOS server as the root user.
$ ssh root@server_ip_address
2. 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
3. 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.
Changing password for user demouser.
Retype new password:
passwd: all authentication tokens updated successfully.
By default on CentOS system, members of the wheel group are granted with sudo access.
4. Now, add to wheel group to grant sudo access:
$ usermod -aG wheel demouser
How to Verify the sudo access ?
Login using new created user or you can switch to the new created user by typing the command:
$ su - demouser
Next, 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.
Now you can use sudo by just typing sudo before any command and give space :
$ sudo ls -la /root
[Need urgent assistance in fixing Linux related errors? We are here for you. ]