How to Add User to Sudoers in Ubuntu

vote/تقييم

In this guide, we will discover: How to Add User to Sudoers in Ubuntu – Easy Beginners Guide 2023
So, let’s begin!

Do you desire to add a user to sudoers in the Ubuntu Linux-based OS but have no clue how to go about it? This guide is for you, as it illustrates several methods to do that.

By Oluwaseun Bamisile | Updated April 12, 2023 | 10 minutes read

In this article, I will show you how to grant a user sudo privileges through the Ubuntu settings in the GUI. You will also learn how to execute this task via the Ubuntu terminal.

To be more specific, I will teach you two commands to add a user in the sudo group through the Ubuntu terminal. These commands include the usermod and gpasswd commands.

Those aside, this guide features an FAQ section. In that section, I will answer about 5 questions people mostly ask regarding this guide’s topic.

Before we move on, you should know that the procedures that will be provided in this guide are based on the Ubuntu 22.04 LTS OS. Hence, the procedures might differ slightly if you use other Ubuntu Linux-based OS versions.

Add User to Sudoers in Ubuntu Through Settings

Add User To Sudoers In Ubuntu Through Settings

One way to grant a user sudo privileges in Ubuntu is through the settings in the Ubuntu GUI. To learn how to do that, follow the procedures listed below.

  1. First, ensure you log into your Ubuntu Linux-based computer using an account with sudo privileges.
  2. Afterward, click the Show Applications icon on the Ubuntu dock. Now, open the settings in Ubuntu by inputting “settings” in the search field and selecting the Settings icon from the search result.

You can also open the settings by clicking the system menu tray at the top right corner of the Ubuntu desktop. Then, select Settings from the options in the system menu tray.

Add User To Sudoers In Ubuntu Through Settings
  1. In the Ubuntu Settings window, select Users among the menus on the left pane.
  1. Following that, click the Unlock… button at the top of the Users page to add users and change settings.
Add User To Sudoers In Ubuntu Through Settings
  1. Accordingly, you will be prompted to input your password for authentication. Hence, input your password in the provided input field, then click the Authenticate button.
  1. Now, select the user you wish to add to sudoers, then turn on the Administrator toggle under Account Settings.
Add User To Sudoers In Ubuntu Through Settings

Add User to Sudo Group in Ubuntu Through Terminal

Another way you can add a user to the sudo group in Ubuntu is by running a particular command in the terminal. As a matter of fact, there are various commands you can use to add a user to the sudo group in Ubuntu.

However, we will focus on only two commands in this section. These commands are the usermod command and gpasswd command.

Thus, the following sub-sections will show you how to use these commands to grant a user sudo privileges in Ubuntu.

How to Add User to Sudo Group Using Usermod Command

  1. Ensure you’re logged into your Ubuntu system as a root user or with an account with sudo privileges. Then, right-click any free area on the Ubuntu desktop and choose Open in Terminal from the context menu.
Add User To Sudo Group In Ubuntu Through Terminal
  1. When the terminal opens, execute the command below. However, replace “username” in the command with the username of the user you wish to add to the sudo group.
sudo usermod -aG sudo username

For instance, if I wish to add a user named “itechguide”, below is what the command should look like.

sudo usermod -aG sudo itechguide
Before the command runs, you will be asked to input your password. Hence, input your password and press the enter key on your keyboard.

Also, note that characters won’t be visible while typing your password in the Ubuntu terminal.

  1. After doing all that, you can confirm if the user has been added to the sudo group by executing the command below. However, replace “username” with the username of the user.
id username

For this demonstration, the username of the user is “itechguide”. So, below is what the command should look like.

id itechguide
Add User To Sudo Group In Ubuntu Through Terminal
  1. After running the prior command, the output should include “27(sudo)”, indicating the user has been added to the sudo group.

Add User to Sudo Group Using Gpasswd Command

  1. Sign into your Ubuntu computer as a root user or with an account in the sudo group.
  2. Next, open the app menu by clicking the Show Applications icon on the Ubuntu dock. Then, input “terminal ” in the search field and choose the Terminal program from the search result.
Add User To Sudo Group In Ubuntu Through Terminal
  1. In the Ubuntu terminal, type the following command and press the enter key. However, replace “username” with the username of the user you wish to add to sudoers.
sudo gpasswd -a username sudo

For example, if I want to add a user with a username of “John” to the sudoers, below is what the command should look like.

sudo gpasswd -a john sudo
  1. By doing that, you will be prompted to input your password – do so and press the enter key on your keyboard. Hence, the user should be added to sudo group.
Add User To Sudo Group In Ubuntu Through Terminal

Frequently Asked Questions

Frequently Asked Questions
1. Who Is A Sudo User?

A sudo user is a regular Linux user with administrator privileges to run commands and perform tasks as a root user. Basically, a sudo or a root user can do things in Linux that a regular user can’t.

For example, a sudo user can add a new user and also access sensitive files. As a matter of fact, a sudo user can add another user to the sudo group in Linux.

2. How To Add A User To Sudo File In Ubuntu?

To add a user to the sudo file in Ubuntu, follow the steps below.
a) First, ensure you log into your Ubuntu Linux-based computer using an account with sudo privileges.
b) Afterward, click the Show Applications icon on the Ubuntu dock.
c) Now, open the settings in Ubuntu by inputting “settings” in the search field and selecting the Settings icon from the search result.
d) In the Ubuntu Settings window, select Users among the menus on the left pane.
e) Following that, click the Unlock… button at the top of the Users page to add users and change settings.
f) Consequently, you will be prompted to input your password for authentication. Hence, input your password in the provided input field, then click the Authenticate button.
g) Now, select the user you wish to add to sudoers, then turn on the Administrator toggle under Account Settings.

3. What Is The Sudo Command In Ubuntu?

The sudo command in Ubuntu allows sudo users to run commands with root privileges.

4. What Is The Command To Add User To Sudo In Linux?

The command to add a user to sudo in Linux is “sudo usermod -aG sudo username” (without the quotes). However, “username” in the command should be replaced with the username of the user you wish to add to sudo.

5. What Is The Full Form Of Sudo In Linux?

Sudo is the acronym for “superuser do” or “substitute user do”.

My Final Thoughts

Adding a user to sudoers in Ubuntu gives the user administrative/sudo privileges. Thus, the user will be able to perform administrative tasks, run programs as a root user, and execute commands with sudo privileges.

However, only trusted users can be added to the sudo group in Ubuntu. Fortunately, this guide demonstrated multiple methods to add a user to sudoers in the Ubuntu Linux-based operating system.

Precisely, we learned how to execute this task through the settings in the Ubuntu GUI. this guide also taught us two commands to grant a user sudo privileges through the Ubuntu terminal.

Hopefully, you enjoyed this article and found it helpful. If you did, we would value it if you could share your opinions with our community platform at Itechguides Community Forum.

Apart from sharing your thoughts, you can also offer feedback or ask questions regarding this guide’s topic at Itechguides Community Forum. Our team and other community members will be delighted to respond to your questions or feedback as quickly as possible.

Finally, you can visit our Linux how-to page to find other helpful Linux how-to guides.

References and Further Reading

  1. linuxize.com – How to Add User to Sudoers in Ubuntu
  2. Itechguides Community Forum

Leave a Comment