- How to create a new user with admin privileges on Linux
- Must-read security coverage
- What you’ll need
- How to create a sudo-able user on Ubuntu Server
- How to create a sudo-able user on CentOS
- How to remove sudo rights
- Subscribe to the Cybersecurity Insider Newsletter
- Also See
- How to Make a User an Administrator in Ubuntu
- Make a User an Administrator in Ubuntu Through the GUI
- Make a User an Administrator in Ubuntu Through the Command Line
- Method 1: The usermod command
- Method 2: The gpasswd command
- Search
- About This Site
- Latest Tutorials
- How To Create a New Sudo-enabled User on Ubuntu 20.04 [Quickstart]
- Step 1 — Logging Into Your Server
- Step 2 — Adding a New User to the System
- Step 3 — Adding the User to the sudo Group
- Step 4 — Testing sudo Access
- Conclusion
How to create a new user with admin privileges on Linux
Adding a user with admin privileges on Linux is easier than you think. Jack Wallen shows you how.
We may be compensated by vendors who appear on this page through methods such as affiliate links or sponsored partnerships. This may influence how and where their products appear on our site, but vendors cannot pay to influence the content of our reviews. For more info, visit our Terms of Use page.
Must-read security coverage
- Google offers certificate in cybersecurity, no dorm room required
- The top 6 enterprise VPN solutions to use in 2023
- EY survey: Tech leaders to invest in AI, 5G, cybersecurity, big data, metaverse
- Electronic data retention policy (TechRepublic Premium)
If you’re a Linux system admin, you probably find yourself scrambling to keep everything in check every day. There’s a lot to be done and doing this with a nod to security makes the task even more challenging. That’s why you dole out tasks to those admins under you. After all, if you attempt to do everything yourself, eventually you’re going to make a mistake, and mistakes can be disastrous in today’s light speed world of business. You create new users on your Linux servers and let those admins do their thing.
Problem is, when you create a new user, that user doesn’t have admin privileges. What do you do? Let me show you. In fact, I’m going to walk you through the process of creating an admin-ready user on Linux with just a few quick commands. I’ll demonstrate this on both Ubuntu Server 20.04 and CentOS 8, so you should be able to handle the task no matter what distribution you’re on.
SEE: Linux service control commands (TechRepublic Premium)
What you’ll need
How to create a sudo-able user on Ubuntu Server
First, we’ll demonstrate how this is done on Ubuntu Server. Here, you can take care of creating the user with only two commands. The first command will create the new user:
Where USERNAME is the name of the user you want to add.
The adduser command will not only have you create a password for the user, but also have you enter the following (optional) details:
The adduser command will also automatically create the new user’s home directory, so you don’t have to worry about that.
With the new user created, it’s time to give them sudo rights. For this we’ll use the usermod command like so:
sudo usermod -aG sudo USER
Where USER is the new username.
You’ve just created a new user and given them sudo privileges on Ubuntu Server.
How to create a sudo-able user on CentOS
Here we have to take an extra step. First we create the user with command:
Where USER is the username to be added. We include the -m option to ensure the home directory is created along with the user.
Next, we need to set the password for the user. However, we’re going to set the password such that the user will have to change their password upon first login. To do that we first must set an initial password with the command:
Where USER is the new username we created.
This will prompt you to type and verify a new password. Once you’ve set that, you can then expire the password with the command:
Where USER is the new username we created.
Finally, we give the user admin privileges with the command:
sudo usermod -aG wheel USER
Where USER is the new username we created.
There you have it–you’ve created a new user and given them sudo privileges on both Ubuntu and CentOS. Now you only have to hope those users will employ sudo with caution.
How to remove sudo rights
If you find one of your admins not using sudo with respect to your policies, you might have to remove their rights. To do that, you’ll edit the /etc/group file and remove their name from either the sudo or the wheel entry. To do that, issue the command:
Scan through that file for either the sudo (Ubuntu) or wheel (CentOS) entry (Figure A). When you find it, you should see the new user listed. Remove them from that line, save and close the file, and that user will no longer have sudo privileges.
And that’s all there is to creating new users with admin privileges on Linux.
Subscribe to the Cybersecurity Insider Newsletter
Strengthen your organization’s IT security defenses by keeping abreast of the latest cybersecurity news, solutions, and best practices.
Delivered Tuesdays and Thursdays
- Cybersecurity and cyberwar: More must-read coverage (TechRepublic on Flipboard)
Also See
How to Make a User an Administrator in Ubuntu
If you have more than one user on your Linux system, you may not want all of them to perform administrative tasks or mess up private system settings. In this case, you can avoid giving these users administrative rights in Ubuntu. Unauthorized users won’t be able to install or uninstall software on your system, and they won’t be able to change important system settings and configurations. Even if you are not at your computer, unauthorized users cannot perform these tasks because they all need sudo privileges and must know the password for sudo.
However, if you want to grant administrative privileges to a user, this article is for you.
In this article, I describe how to make a user an administrator through the graphical user interface and explain what commands you need to use on the command line to add a user to the sudo (authorized) user group.
We have run the commands and procedures mentioned in this article on an Ubuntu 20.04 and Ubuntu 22.04 system.
Make a User an Administrator in Ubuntu Through the GUI
In order to change user settings through the UI, you need to open the Users tab in the System Settings utility. You can access it through the following two ways:
Enter the ‘users’ keyword in the system Dash and click on the “Users” search result.
Click on the downward arrow located in the top-right corner of your Ubuntu desktop, click on your username in the following view and then click Account Settings from the drop-down.
The Settings utility will open, displaying the Users tab. Please note that only an authorized user can change user settings in Ubuntu. First, you need to unlock the tab in order to make changes as an administrator by clicking the Unlock button located in the top-right corner of the Users view:
This will open the following Authentication dialog where you can provide the password for the authorized user:
Enter the password and then click the Authenticate button. Now you can make changes to any user’s settings. Click on the username of the user you want to make an Administrator.
In the Account Type of the user you will see two buttons; the Standard button and the Administrator button. Click on the Administrator button to make this user an Administrator. As soon as you do this, the user will be given administrative privileges and can now perform all operations that need root rights.
Make a User an Administrator in Ubuntu Through the Command Line
We will describe two ways to make a standard Ubuntu user an Administrator through the command line:
We will use the Ubuntu command line application, the Terminal, to perform this operation. You can open the Terminal either through the system Dash or the Ctrl+Alt+T shortcut.
Method 1: The usermod command
Open the Terminal and enter the following command as sudo as only an authorized user can edit user settings in Ubuntu:
$ sudo usermod -aG sudo “username”
In this example we will use the following command to make a user with the username “sampleuser” an administrator:
$ sudo usermod -aG sudo sampleuser
Enter the password for sudo and the user will be added to the “sudo” group which means that he/she can perform all administrative tasks on Ubuntu.
You can verify that the user is now in the “sudo” group by checking the groups a user belongs to, through the following command:
The following output of the ‘groups’ command for our “sampleuser” indicates that he/she is now part of the sudo group.
Method 2: The gpasswd command
Open the Terminal and enter the following gpasswd command as sudo as only an authorized user can edit user settings in Ubuntu:
$ sudo gpasswd -a “username” sudo
In this example, we are adding the “sampleuser” to the sudo group through the following command:
$ sudo gpasswd -a sampleuser sudo
You can also remove a user from the sudo group through the -r switch in the same gpasswd command:
$ sudo gpasswd -d “username” sudo
In this example, we are removing the “sampleuser” from the sudo group through the following command:
$ sudo gpasswd -a sampleuser sudo
Through the methods described in this article, you can make an ordinary Ubuntu user an Administrator so that they can perform all tasks that require root privileges on the system.
Search
About This Site
Vitux.com aims to become a Linux compendium with lots of unique and up to date tutorials.
Latest Tutorials
How To Create a New Sudo-enabled User on Ubuntu 20.04 [Quickstart]
When managing a server, you’ll sometimes want to allow users to execute commands as “root,” the administrator-level user. The sudo command provides system administrators with a way to grant administrator privileges — ordinarily only available to the root user — to normal users.
In this tutorial, you’ll learn how to create a new user with sudo access on Ubuntu 20.04 without having to modify your server’s /etc/sudoers file.
Note: If you want to configure sudo for an existing user, skip to step 3.
Step 1 — Logging Into Your Server
SSH in to your server as the root user:
Step 2 — Adding a New User to the System
Use the adduser command to add a new user to your system:
Be sure to replace sammy with the username that you want to create. You will be prompted to create and verify a password for the user:
OutputEnter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Next, you’ll be asked to fill in some information about the new user. It is fine to accept the defaults and leave this information blank:
OutputChanging the user information for sammy Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n]
Step 3 — Adding the User to the sudo Group
Use the usermod command to add the user to the sudo group:
Again, be sure to replace sammy with the username you just added. By default on Ubuntu, all members of the sudo group have full sudo privileges.
Step 4 — Testing sudo Access
To test that the new sudo permissions are working, first use the su command to switch to the new user account:
As the new user, verify that you can use sudo by prepending sudo to the command that you want to run with superuser privileges:
For example, you can list the contents of the /root directory, which is normally only accessible to the root user:
The first time you use sudo in a session, you will be prompted for the password of that user’s account. Enter the password to proceed:
Output:[sudo] password for sammy:
Note: This is not asking for the root password! Enter the password of the sudo-enabled user you just created.
If your user is in the proper group and you entered the password correctly, the command that you issued with sudo will run with root privileges.
Conclusion
In this quickstart tutorial, we created a new user account and added it to the sudo group to enable sudo access.
For your new user to be granted external access, please follow our section on Enabling External Access for Your Regular User.
If you need more detailed information on setting up an Ubuntu 20.04 server, please read our Initial Server Setup with Ubuntu 20.04 tutorial.
Get Ubuntu on a hosted virtual machine in seconds with DigitalOcean Droplets! Simple enough for any user, powerful enough for fast-growing applications or businesses.