Create a Sudo User on CentOS - How to do it ?
- Create a Sudo User on CentOS - How to do it ?
The sudo command gives a mechanism for granting administrator privileges, ordinarily only available to the root user, to normal users.
Here at LinuxAPT, 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.
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
This article covers 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.
Performing server administration as a non-root user is a best practice.
For security, your first task when deploying a CentOS instance is to create a non-root user with sudo access.
How to Add a New User Account on CentOS Linux System ?
1. To Create a new user account with the adduser command:
# adduser example_user
2. Set a strong password for the new user (new_user) with passwd.
# passwd new_user