Select the Gcore Platform

Gcore Edge Solutions
Go to Gcore Platform →
Products:
  • Edge Delivery (CDN)
  • DNS with failover
  • Virtual Machines
  • Bare Metal
  • Cloud Load Balancers
  • Managed Kubernetes
  • AI Infrastructure
  • Edge Security (DDOS+WAF)
  • FaaS
  • Streaming
  • Object Storage
  • ImageStack (Optimize and Resize)
  • Edge Compute (Coming soon)
Gcore Hosting
Go to Gcore Hosting →
Products:
  • VPS Hosting
  • Dedicated Servers
  • SSL Certificates

Share

How to Add User to Sudoers in Debian

For those administering Debian-based systems, one fundamental skill is managing user permissions to ensure both security and functionality. Among the most crucial tasks is understanding how to add a user to the sudoers list, granting them elevated privileges to perform administrative actions. In this article, we will guide you on how to delve into the complexities of this process, providing clear instructions and insights to make user management in Debian both straightforward and secure.

Adding User via Terminal

To add a user to the sudoers in Debian via the terminal, you can either add the user to the sudo group (simpler method) or modify the /etc/sudoers file for more fine-grained control. Here are the steps for both methods.

#1 Login to your Debian System

First, you’ll need to access your terminal. If you’re not logged in as the root user, you’ll have to switch to a user that already has sudo privileges.

#2 Adding a User to the sudo Group

The easiest way to give a user sudo access is to add them to the sudo group. By default, Debian is configured in a way that members of the sudo group are permitted to use the sudo command.

sudo usermod -aG sudo username

Replace username with the name of the user you want to grant sudo privileges.

#3 Verify the User is Part of the sudo Group

To ensure the user has been added to the group, you can use the groups command:

groups username

You should see sudo in the list of groups for that user.

#4 Alternative Method: Modify the /etc/sudoers File

If you want to grant specific permissions or avoid adding the user to the sudo group, you can edit the /etc/sudoers file.

1. Open the sudoers file using visudo:

sudo visudo

The visudo command ensures that you do not make syntax errors that can lock you out of the system.

2. Add the user with appropriate permissions:
Navigate to the section where individual user permissions are defined. To give full access, add:

username ALL=(ALL:ALL) ALL

For specific permissions, consult the sudoers man page.

3. Save and Exit:

Depending on the editor you are in:

  • For nano (default for some Debian installations): CTRL + O to write changes, then Enter, and CTRL + X to exit.
  • For vi: Press Esc, type :wq, and press Enter.

Note: Always use visudo when editing the sudoers file. Directly editing can lead to errors that make your system unusable.

#5 Test the Configuration

Switch to the user account and try to run a command with sudo to ensure the permissions are applied correctly:

su - username
sudo apt updat

If everything is set up correctly, the user should be prompted for their password and then be able to execute the apt update command with elevated privileges.

Congratulations! you’ve now successfully added a user to the sudoers on Debian. It’s crucial to be careful when giving sudo privileges, as a sudo user has a lot of power and can potentially harm the system if not used cautiously.

Related learning articles

Subscribe to a useful newsletter

Favorable offers and important news once a month. No spam.