“How to add an user to the Sudoers list?”, a quite common question asked by many. So here in this post i am writing the most convenient method to do it. 🙂
But before i start with the process to add an user to the sudoer list, let me tell you why we do this.
On adding a new user to the sudoers list that user will be able to run commands and open files with root user privilege.
Process to add an user to the sudoers list:
- Open terminal.
- Type the following command
$su -c visudo
Enter the root password.when asked.
- You can move the cursor using up/down arrow key. Move down to the line containing
root ALL=(ALL) ALL
- press “i” to activate insert mode then add the following code just after the above line
<new username> ALL=(ALL) ALL
. So now it looks something like this
## Allow root to run any commands anywhere root ALL=(ALL) ALL <username> ALL=(ALL) ALL
- You might need to remove the # infront of the line %wheel ALL=(ALL) ALL, mine was already done so i didn’t have to remove it. So now it looks like
## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL
- Press Esc to come out of insert mode, then type “:wq” in the command line and press enter to save and quit from vi. And that’s it you have done it. 😀
But here in this step number 4 you assign a root privilege to the user which again compromises your security. Once added to the sudoers list the user can change the password for other users, hence it is quite not advisable if your machine got multiple users logging in as your security might get compromised.
Instead of giving root privilege to for all the commands you can specify the commands with root privilege that the user might use.
<new username> ALL=/usr/bin/yum
If your machine is common to many users i would suggest you to allow only particular command to be executed with root privilege else if you are the sole user then like me you may allow all commands to be executed by the user with root privilege.
Here is a slideshow to show how my sudoers file is: