If you have more than one user on your Linux system, you might not want all of them to perform administrative tasks or mess up with private system settings. In that case, you can avoid giving administrative privileges on your Ubuntu system to those users. Unauthorized users can not install or uninstall software on your system and neither can they change key system settings and configurations. Even if you are away from your computer, any unauthorized user cannot perform these tasks as all of them require sudo rights and need to know the password for sudo.
However, if by will you want to grant administrative rights to a user, this article is here for your help.
In this article, we will describe how to make a user an Administrator through the Graphical User Interface and also explain what commands to use in the command line in order to add a user to the sudo (authorized) user group.
We have run the commands and procedures mentioned in this article on an Ubuntu 18.04 LTS 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:
- Through the usermod command
- Through the gpasswd command
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:
$ groups “username”
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.