Introduction
If you are working with CentOS 8, you should know what are the critical commands to use with it. One of these is the sudo
command. This command is very useful for creating new users. With the sudo
command, you can grant certain users special administrative privileges. Typically, these privileges are only accessible to the root user. If you are making a regular user, you can use this command to give them special access without changing the /etc/sudoers
file on the server.
This tutorial will help you understand how to use this command. We will detail the individual steps you need to take to create a new sudo-enabled user on CentOS 8.
How to Make a New User that is Sudo-Enabled?
Follow these steps to create a new sudo-enabled user on your server.os
1. Perform Server Login
First of all, you have to log into the server as the root user. Log in with the following:
1 |
$ ssh root@your_server_ip_address |
Substitute in your own server’s IP address or hostname.
2. Add New User
Next, we will add a new user. For this purpose, we will use the adduser
command. Let’s say we want to add a new user called sammy
:
1 |
# adduser sammy |
You can substitute sammy with your preferred username. The next step is to add the password for your user. Use the passwd
command as follows:
1 |
# passwd sammy |
The system will ask you to enter the new password two times for confirmation:
Replace sammy with your chosen username.
3. The Wheel Group
Now we will add the user to the wheel group. If you want to give administrator privileges to an existing account, then you can skip to this step right away. We will use the usermod
command to add the user to the group:
1 |
# usermod -aG wheel sammy |
The reason why we are doing so is that all users in the wheel group have full sudo
access and privileges.
4. Sudo Access
Lastly, you can check and confirm whether or not your new user has acquired the sudo
permissions. To begin with, we shall switch from the root user to the new user using the su
command:
1 |
# su - sammy |
Run the test by running sudo
with the command you wish to use with your new permissions and privileges:
1 |
# sudo command_to_run |
Let us assume that we want to list the contents of the /root
directory. Normally, only the root user can visualize the contents of this file:
1 |
$ sudo ls -la /root |
The system will require you to enter your account password if you are using sudo for the first time:
Enter your password in the field to move forward. Remember, you need to enter the account password, not the root password. In case you are in the right wheel group with permissions enabled, the command will run successfully and show you the results. This is confirmation that you have received sudo
with root privileges.
Conclusion
With the help of this tutorial, you can make a new account as well as grant it administrative privileges. The simplest route to take is to add it to the wheel group for sudo
access.
Further, you can take a look at our other tutorials involving CentOS which you can find on our blog:
Happy Computing!
- How To Enable, Create and Use the .htaccess File: A Tutorial - March 8, 2023
- An Overview of Queries in MySQL - October 28, 2022
- Introduction to Cookies: Understanding and Working with JavaScript Cookies - October 25, 2022
- An Overview of Data Types in Ruby - October 24, 2022
- The Architecture of Iptables and Netfilter - October 10, 2022