How to create a sudo user in CentOS 8. The sudo command is used to grant an administration privilege, also known as root privileges to normal users. In this Linux CentOS tutorial, I will show you simply how to create/add and new user on your CentOS 8 system and how to change it into a sudo user account. It’s one of the best security practices, in any Linux distribution which is to use a sudo user account instead of a root user account.
Let’s dive into the tutorial and see how to create a user account with sudo privileges in your CentOS 8 system.
How to Create a Sudo User on CentOS 8
Please follow the steps below to create a sudo user account in your CentOS 8 server, Also this tutorial might be used for other distributions as well.
First of all, you must log in to your CentOS 8 server as a root user.
$ ssh root@<server_ip_address>
To log in to your CentOS 8 Server you can use ssh, here is the syntax of using ssh for logging in to your CentOS server as a root user.
Now the First step is done, You are successfully logged in to your server as a root user, Now you need to create a new user using
adduser command. It is a command that is used in Linux systems to add/create a new user in the system. Now Let’s create a demouser account in your CentOS 8 server using
$ adduser demouser
demouser is the name that I choose for the new account that I need to create on my CentOS 8 system, You are able to use any name with your own system.
Now you need to set a new password for the account you’ve created on your CentOS 8 server. To that you can use
passwd command and specify the user account name after that to set a new password for that account. Let’s set a new password for your new user account.
$ passwd demouser
passwd command will prompt to ask a confirm the new password. Use a strong password the contains multiple characters, numbers, and special characters, make sure it’s a strong password before use.
Changing password for user demouser.
Retype new password:
passwd: all authentication tokens updated successfully.
In CentOS, By default members in
wheel group are
granted sudo access. Now newly created user account is ready to add to
wheel group and grant sudo access.
$ usermod -aG wheel demouser
Congrats, now you have created a sudo user account in your CentOS 8 server, So now we need to verify whether it’s working or not. Let’s see how to verify the newly created sudo user account.
Related Article: Rosetta Stone vs. Duolingo, A Comprehensive Comparison Review
Verify the sudo access with a new account
Let’s switch in to the new account first, To log in to the new sudo account you can use
su command. Let’s see how to switch using
$ su - demouser
Using this command you can easily switch to the newly created user account. After a switch to your new account now let’s try some commands with the sudo command for a test.
$ sudo whoami
If your account has successfully added to the wheel group and it has root privileges access, It will provide output
root for the
sudo whoami command.
Now you can use any command with sudo. Type commands after the
sudo. For Example,
With this tutorial, you gain knowledge of how to create a new user with sudo access in the CentOS 8 server. After creating your new account you can use any command with sudo privileges.
Feel free to add your valuable feedback and any suggestions about this tutorial and keep in touch with Think & Free for more tutorials and educational content like this.