How to Add User to Sudoers in Debian
Sudo (for superuser do) is a command-line utility that allows users to run commands with root privileges.
It gives users admin-level permissions to run programs on your machine.
Using sudo is more secure than opening a session as root. The root password is protected as
sudo prompts for the current user's password.
You can temporarily grant extra privileges to users. The access is removed without changing any password.
This tutorial covers how to add a new user to sudoers in the Debian Linux system.
1. Log in as the Root User
Before adding a user to your system, log in to your server as the root user:
In the above line, replace ip_address with the IP address of your server.
2. Add a New User in Debian
You can create a new user with the adduser command as a root user. Append the required user account name to the command:
For example, add a new account sudo_user with the command:
The output looks like this:
The sudo command creates a home directory for the user and copies all the necessary files.
Enter the password for the user account and retype to confirm it.
Set a strong password for accounts with sudo access.
In the terminal, you will be prompted to change the user information.
Add the details in the text editor or press Enter to leave the fields blank.
3. Add User to the Sudo Group
Users that have root privileges can add any account to the sudo group.
Everyone in the group automatically gets sudo access to Debian and Ubuntu operating systems.
Run the command shown below and add a user to the sudo group:
usermod -aG sudo username
The command consists of the following components:
usermod command modifies a user account.
-aG is an option that adds the user to a specific group. The -a option adds a user to the group. It does that without removing them from the current groups. The -G option is used to state where to add the existing user.
sudois the group that is appended to the options mentioned above.
username is the user account you want to add to the sudo group.
Verify the new Debian sudo user is added to the group with the command:
getent group sudo
The output lists all users in the group.
4. Verify Sudo Access in Debian
To verify the new user has sudo privileges:
Switch to the user account you have created. You can do it by running the command shown below.
You have to replace the username with the name of your user account-
su - username
Run a command that requires superuser access. For example, sudo whoami will show you that you are the root.
5. Using Sudo
If you want to run a command with root access, type in sudo and enter the required command.
For example, you can view details for the root directory, run the ls tool as the following -
sudo ls -la /root
Enter the user’s password as prompted. The terminal will show the contents of the root directory.
You only have to enter the password once for the same session.
Sudo allows individual users to run commands that require special privileges.
You can revoke access easily after you execute the commands as a root account.
Debian's default configuration allows users in the
sudo group to run any command via sudo.
The tutorial covers how you can add users to sudoers in Debian.
Check out more insightful tutorials on CloudPanel.