-   Linux - Newbie (
-   -   User not in the sudoers file (

ersek 05-15-2009 04:55 AM

User not in the sudoers file

I'm working with Ubuntu 8.10, and trying to type the command:

sudo su -
I got the following result

user is not in the sudoers file.  This incident will be reported.
I have no root user enabled, how could I reinsert the user inside the sudoers file?


Robhogg 05-15-2009 08:28 AM

Is your current user in the admin group (run id and see if it's listed)? By default in Ubuntu, all members of the admin group are allowed to use sudo. If not, have you got another user set up who is in the admin group?

If the answer to both of these is no, you will need to boot your PC from a live disk (you have to have root privileges to alter sudoers), su to root (or use sudo -i ), then run:

mount /dev/ubuntupartition /mnt
chroot /mnt bash # then run either:
usermod -G admin username # or

The latter command will open sudoers in an editor (with syntax checking when you close it). Add a line:

username ALL=(ALL) ALL
Save, reboot, and your user should be able to access sudo.

BTW, to get a root shell in Ubuntu I would normally use sudo -i or sudo bash instead of sudo su -.

jschiwal 05-15-2009 08:58 AM

Or become a member of the admin group instead of explicitly adding a user in sudoers. The first user is normally automatically made a member during installation. The first user and add you or you can edit /etc/groups from a live distro, adding your user after the colon.

Robhogg 05-15-2009 09:08 AM


Originally Posted by jschiwal (Post 3541754)
Or become a member of the admin group instead of explicitly adding a user in sudoers...

Yes, 'tis what this command does:

usermod -G admin username
... though I probably should have pointed that out :).

ersek 05-15-2009 09:33 AM

Thanks for your proposal,

however I found a solution in the following thread:

which allow to solve this issue without using a live distro :-)

jschiwal 05-16-2009 02:09 AM


Originally Posted by Robhogg (Post 3541764)
Yes, 'tis what this command does:

usermod -g admin username
... though I probably should have pointed that out :).

Well, since he can't use sudo, in the first place. The proper way of doing it won't work.

I don't like the idea of adding individual users to the sudoers file when unnecessary. Often the only edit that is needed is uncommenting an entry already there.

Robhogg 05-16-2009 05:13 AM


Originally Posted by jschiwal (Post 3542527)
Well, since he can't use sudo, in the first place.

Except that what I'd suggested was to boot from a live disk, become root in the live environment and then chroot into the Ubuntu partition, before issuing the usermod command. Just done this using a Mint live CD, and can confirm that it works.

The error that you could have pulled me up on was that I'd used usermod -g ... rather than usermod -G ... - the former command changes the user's primary login group, rather than adding the user to a group :redface: (I've now corrected this in my original post).

saxophobe 06-04-2009 07:06 PM

Ok, I have been trying to do this for the past couple of hours with little success. In answer to your questions, I'm using CentOS 5.3, not Ubuntu, so I have the root user that is a member of the Admins group. And I can get into visudo, but I have to use /usr/sbin/visudo for some reason. In any case, every instruction I've seen says to save/close and reboot. How do you do that?!?!!?? I hate vim. I like nano, which has all the commands at the bottom, which is very helpful for an aging ID10T like me! So now, when I try to edit the sudoers file, I get the following error:


Found a swap file by the name "/etc/.sudoers.tmp.swp"

"/etc/sudoers.tmp" 94L, 3185C
Press ENTER or type command to continue
So, 1) How do I prevent this error message from coming up? and 2) How do I save/close in visudo?

Thanks in advance for your time!

chrism01 06-05-2009 01:27 AM



is a temp backup file created by vi/vim when being used. Start by deleting it before starting the editor. Normally it only exists if the editor crashed or you broke out of it.
Now use visudo, do your edits, the use the 'esc' key then


to exit and save.
Try the cmd vimtutor once you're up and running again.

jschiwal 06-05-2009 02:03 AM

I don't use CentOS, but I think you need to add the user to the wheel group instead of the admin group.

There is a line near the bottom of the sudoer file that may be commented out. You simply need to delete the "# " at the beginning of the line to enable it. Then add the user to the wheel group.

When adding groups or editing the sudoers file, you may need to reboot for sudo to operate correctly.

saxophobe 06-09-2009 01:35 PM

Folks, thanks for all your help! I'm not sure where I am right now with this, as I edited the file so I do not get the error that says my account does not belong to the sudoers group; I had to add my account to the command section under root to get it to work. I tried the suggestion of adding to the wheel group, but still got the error, I even added my account to the wheel group to make sure, but no dice.

In any case, now I can edit this file using sudo! Now I have to figure out why I can't run ifconfig?!?!?! Every time I do, I get the following response:


bash: ifconfig: command not found

sudo: ifconfig: command not found
This happens even when I'm in ROOT! But this is really a different issue. I'll post elsewhere on this one.

All times are GMT -5. The time now is 03:14 AM.