[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedMarch 16, 2023

How to Add User to Sudoers in Ubuntu

How To Add User To Sudoers In Ubuntu

In this article we’ll show you two ways to grant sudo privileges to a user. The first one is to add the user to the sudoers file . This file contains information that controls which users and groups are granted with sudo privileges, as well as the level of the privileges.

sudo is a command-line program that allows trusted users to execute commands as root or another user.

The second option is to add the user to the sudo group specified in the sudoers file. By default, on Debian based distributions like Ubuntu and Linux Mint, members of the “sudo” group are granted with sudo access.

 

Adding User to the sudo Group

On Ubuntu, the easiest way to grant sudo privileges to a user is by adding the user to the “sudo” group. Members of this group can execute any command as root via sudo and prompted to authenticate themselves with their password when using sudo.

We’re assuming that the user already exists. If you want to create a new user, check this guide.

To add the user to the group run the command below as root or another sudo user. Make sure you change “username” with the name of the user that you want to grant permissions to.

usermod -aG sudo username

Granting sudo access using this method is sufficient for most use cases.

To ensure that the user has sudo privileges, run the whoami command:

sudo whoami

You will be prompted to enter the password. If the user has sudo access, the command will print “root”:

root

If you get an error saying “user is not in the sudoers file”, it means that the user doesn’t have sudo privileges.

 

Adding User to the sudoers File

The users’ and groups’ sudo privileges are defined in the /etc/sudoers file. Adding the user to this file allows you to grant customized access to the commands and configure custom security policies.

You can configure the user sudo access by modifying the sudoers file or by creating a new configuration file in the /etc/sudoers.d directory. The files inside this directory are included in the sudoers file.

Always use visudo to edit the /etc/sudoers file. This command checks the file for syntax errors when you save it. If there are any errors, the file is not saved. If you open the file with a text editor, a syntax error may result in losing the sudo access.

Typically, visudo uses vim to open the /etc/sudoers. If you don’t have experience with vim and you want to edit the file with nano , change the default editor by running:

EDITOR=nano visudo

Let’s say you want to allow the user to run sudo commands without being asked for a password. To do that, open the /etc/sudoers file:

visudo

Scroll down to the end of the file and add the following line:

/etc/sudoers
username  ALL=(ALL) NOPASSWD:ALL

Save a file and quit the editor . Do not forget to change “username” with the username you want to grant access to.

Another typical example is to allow the user to run only specific commands via sudo . For example, to allow only the mkdir and rmdir commands, you would use:

/etc/sudoers
username ALL=(ALL) NOPASSWD:/bin/mkdir,/bin/rmdir

Instead of editing the sudoers file, you can accomplish the same by creating a new file with the authorization rules in the /etc/sudoers.d directory. Add the same rule as you would add to the sudoers file:

echo "username  ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/username

This approach makes the management of the sudo privileges more maintainable. The name of the file not important. It is a common practice the name of the file to be the same as the username.

 

Conclusion

Granting sudo access to a user in Ubuntu is a simple task; all you have to do is to add the user to the “sudo” group.

Keep reading
How to understand Squid proxy and how to configure Squid proxy.
March 5, 2023

How to understand Squid proxy and how to configure Squid proxy.

How To Understand Squid Proxy And How To Configure Squid Proxy. A proxy is a server located between two networks; in this case, the most common implementation of a Squid proxy is the division between user computers and devices and the internet, divided or separated by a proxy server in the middle.…

Read article
How to install Debian 11
March 3, 2023

How to install Debian 11

How To Install Debian 11 Connect to java/html5 console, (here you can find an article that will show you how) How to access java/html5 console : Mount ISO: Virtual media > Connect Virtual Image > Map CD/DVD Click on: Connect Virtual Media. Click on: Map CD/DVD. Now click on: Map Device. Next…

Read article
How to understand what is RDP.
March 3, 2023

How to understand what is RDP.

How To Understand What Is RDP. Remote Desktop Protocol (RDP), a secure network communication protocol offered by Microsoft, allows users to execute remote operations on other computers. It facilitates secure information exchange between remotely connected machines over an encrypted communication…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00