Benaiah\’s Computer Experiences

August 15, 2008

Add User to “sudoers” File

Filed under: Linux, ubuntu — Tags: , — Benaiah @ 10:17 am

To give a user the ability to use the “sudo” command you must add them to the “sudoers” file.  Here’s how.

Thanks to ubuntucat (see comment below) for the following suggestion!  The easiest way to allow a user to sudo is to simply run the following command from the Terminal:

To open the Terminal:

Applications >> Accessories >> Terminal

Once the Terminal is open type:

sudo adduser username admin

This must be done from an account that already has sudo abilities or else from the root account.

If for some reason you have to manually edit the “sudoers” file keep reading!

Open the file “sudoers” located at /etc/sudoers using your favorite text editor.  You must have root permissions to be able to edit this file so you will want to open your editor from the command line.

To use gedit you would do the following:

Open the Terminal and type:

sudo gedit /etc/sudoers

If you want to use vim you can simply enter the following into the Terminal:

sudo visudo

Once you have the sudoers file open, scroll down to the line:

root   ALL = (ALL)    ALL

Add the folling line below the root line (replacing “user” with the name of the account you wish to give sudo access to)

user   ALL = (ALL)    ALL

Save and close the file.  The new user has now been added to the “sudoers” file and can use the “sudo” command.

15 Comments »

  1. You can also give a user the ability to sudo without having to edit the /etc/sudoers file:

    sudo adduser username admin

    By the way, sudo visudo is preferable to a manual sudo texteditorofchoice /etc/sudoers, since sudo visudo will check the syntax of the file and not allow you to save it if there’s bad syntax.

    Comment by ubuntucat — August 15, 2008 @ 12:53 pm

  2. Nice! Been wondering about this for a while now.

    Comment by Zoot — August 15, 2008 @ 2:53 pm

  3. How do i remove user from sudoer file with a similar command line such as ‘sudo adduser username admin’

    Comment by Roy — March 22, 2009 @ 9:15 am

    • Yeah,is there anyway to do it?
      I found somewere a command deluser,but I’m a little afraid of using it,’cause I’m not sure it doesn’t remove the user itself!
      Can anyone tell me if it is sure and doesn’t delete the user?

      Comment by Sukoru — July 7, 2011 @ 2:27 am

  4. this makes no sense to me. if you can’t do the command “sudo” then why use the “sudo” command to get sudoer privileges? circular reasoning i think…i need another way around this.

    Comment by enoga — June 6, 2009 @ 6:29 am

    • If you haven’t already got a user that can sudo, then you will need to do this as root, in which case you don’t prefix your commands with ‘sudo’

      Comment by searbe — June 28, 2009 @ 8:14 am

  5. will this work on edubuntu 7.04

    Comment by john — April 19, 2010 @ 4:54 am

  6. Thank you. I also followed another website http://www.techgaun.com/2011/12/adding-regular-user-to-sudoers-file-in.html which explained me three ways of doing the same task. Your’s way is also great. Thanks for helping me out.

    Comment by Anuh — December 31, 2011 @ 3:08 pm

  7. it works when you have at least one standard account.

    Comment by Harish Chaudhary — January 30, 2012 @ 6:56 am

  8. By the way, editting the sudoers file is unnecessary after you add your user to the admin list, as the default sudoers file already contains an entry for all users in the admin group.

    However, when you add a logged in user to a new group, that user->group association won’t take place until after they logout and back in. After that, being the admin group will be sufficient to have sudo access.

    Comment by Pessime — January 30, 2013 @ 9:33 pm

  9. It’s great to see this place is finally getting the attention it totally deserves. Keep up the terrific work.

    Comment by single cup — February 23, 2013 @ 5:55 am

  10. Perfect now i can say i’m a sudoer

    Comment by Maxime — March 10, 2013 @ 3:42 am

  11. I am on Debian 7.0 LXDE stable version, just freshly installed the system via CD iso. I first tried to open the file via pcmanfm, but permission denied, and a blank leafpad file with sudoers displayed. I then tried the terminal commands given above, but still permission is denied, specifics as below:
    a@SAM:/$ cd /etc
    a@SAM:/etc$ sudo nano /etc/sudoers
    [sudo] password for a:
    a is not in the sudoers file. This incident will be reported.
    a@SAM:/etc$ sudo visudo
    [sudo] password for a:
    a is not in the sudoers file. This incident will be reported.
    a@SAM:/etc$ pwd
    /etc
    a@SAM:/etc$

    Comment by Andrew — May 11, 2013 @ 8:00 pm

    • On a fresh install, your default user should be admin, and already part of the sudoers file. you’ll need to do add users to the sudoers file from that 1st user.

      Comment by Pessime — June 27, 2013 @ 3:44 pm


RSS feed for comments on this post. TrackBack URI

Leave a reply to Roy Cancel reply

Blog at WordPress.com.