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.

  3. You can move the cursor using up/down arrow key. Move down to the line containing
    root ALL=(ALL) ALL
  4. 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
  5. 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
  6. 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.

For example:

<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:

Adding Users to Sudoers List

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s