Adding Users to Sudoers List

โ€œ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:

  1. Open terminal.

  2. Type the following command

$su -c visudo

Enter the root password when asked.

  1. You can move the cursor using up/down arrow key. Move down to the line containing
root ALL=(ALL) ALL
  1. 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
  1. You might need to remove the # in front 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
  1. 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. ๐Ÿ˜€

Here is a slideshow showing the sudoers file:

Sudoers file screenshot 1

Sudoers file screenshot 2


Security Considerations

But here in 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 has multiple users logging in as your security might get compromised.

Instead of giving root privilege for all the commands you can specify the commands with root privilege that the user might use.

For example:

<new username>  ALL=/usr/bin/yum

If your machine is common to many users I would suggest you to allow only particular commands 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.

Subscribe to Codenamesubho Newsletter

One update per week. All the latest posts directly in your inbox.