Tuesday, December 4, 2012

User is not in the sudoers file. How to add the user to the sudoers file?

I installed Debian few times on my systems and evey time I start using it I find out that the sudo command does not work with my user account.  I am a big fan of Ubuntu and I am used to it as I used for the last few years and I think the sudo command always worked for me out of the box.  so here is how you get the sudo command to work.
First:  all you need to do is add the following line to the sudoers file in /etc/sudoers
user_name   ALL=(ALL) ALL
Replace user_name with your own user ID
however, you have to use the visudo command to edit the file while being root
so, here is what you need to do:
open a new terminal
switch to root, type "su" then enter the root password
type "visudo" and you will see the sudoers file opened for editting
go to the end of the file and type the line
user_name  ALL=(ALL) ALL
Again, Make sure you replace user_name with your own user ID
then hold the CTRL key and press "o" to save the file and confirm by pressing enter
now hold CTRL key and press "x" to exit the program
type "exit" to exit root mood
then now type sudo gedit and enter your password
if everything went well, you should see the gedit program
you are done,
Enjoy,


Update:  How to add a user to Sudoers account in Ubuntu?
I found out that if you create a new account using "adduser" you do not get the sudoers group by default
so,
  1. Open a terminal using another account such as root or main account
  2. type "sudo nano /etc/sudoers"
  3. Go to the end of the file and type the following
    1. user_name ALL=(ALL)ALL
    2. Replace user_name with your new user name
    3. Save the file and exit "Ctrl x" when asked type y and press Enter to confirm the file name
  4. now log out and login using that user_name and you should have the sudo command working
I tested this process on an embedded Debian system, works great.

No comments:

Post a Comment