How to Add a User to the Sudoers List in Linux
As a Linux administrator, you may need to give a new user elevated permissions to perform certain tasks. One way to do this is by adding them to the sudoers list. The sudoers list grants root access to users in specific groups, allowing them to run commands as if they were the root user. Here’s how to add a user to the sudoers list in Linux.
1. Log in as the root user or a user with sudo privileges.
2. Open the /etc/sudoers file with your preferred editor.
You can use the Vim editor with the following command:
sudo vim /etc/sudoers
Alternatively, you can use nano, which is simpler for new users:
sudo nano /etc/sudoers
3. Scroll down the file until you find the following line:
root ALL=(ALL:ALL) ALL
This line gives the root user full sudo permissions. Below this line, you can add a new entry for the user you want to give sudo access.
You can add the user to the wheel group with the following command:
%wheel ALL=(ALL:ALL) ALL
4. Save the file by pressing Ctrl + O (in Vi) or Ctrl+X, Y (in nano).
5. Exit your editor and run the following command:
id username
Replace “username” with the name of the user you want to add to the sudoers list. This command will display their user ID and group ID, which you will need to add them to the wheel group.
6. Run the following command, replacing “userID” and “groupID” with the IDs displayed in the previous step:
usermod -aG wheel username
7. Finally, to confirm that the user has been added to the sudoers list, log in as that user and run the following command:
sudo whoami
If the user is a member of the wheel group, they should be able to run commands with root privileges using the sudo command.