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.

5 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

  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


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.