4

Possible Duplicate:
How do I add myself back as a sudo user?

jiewmeng is not in the sudoers file.  This incident will be reported.

Whats happening? Its a home PC with me as the only user. I noticed this only happended recently. Perhaps after some recent update. I was running sudo add-apt-repository ...

Jiew Meng
  • 10,347

1 Answers1

5

It seems unlikely that just adding a repository would have removed you from sudoers (or more likely, the admin group).

Are you still in the admin group?

Simply run groups from a terminal. You should see a list come out. You're looking for the word admin. If that's in there, this isn't your issue.

The easiest way to restore your sudo rights is to reboot in recovery mode (hold left-shift at boot, select a recovery mode kernel, boot to the root prompt). Once in there you might be able to run (swap oli for your username) :

adduser oli admin

But I've seen some thing that suggest this might not work from a recovery console. Try it. If that doesn't work, or you want to check, run nano /etc/group

Look for the admin group and add your username to the end, like so:

admin:x:115:oli

You should then be able to reboot and be in the right group.

Has something melted /etc/sudoers?

Unfortunately you can't read /etc/sudoers unless you're root. So back to recovery mode (as above). Once you're in there run nano /etc/sudoers. You're looking for a pair of lines like this:

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

If that's there, this isn't your problem. If it's commented out or missing, whack it back in there!

Oli
  • 293,335
  • I don't mean adding repository removed me from sudoers, I think it was actually an update or perhaps I did something wrong. Ok I boot into recovery mode later, but I'd mark this as correct 1st. It looks right – Jiew Meng Nov 26 '11 at 02:47
  • 1
    I did something similar a while back. The other trick to know which Oli doesn't have here is that when you use recovery mode, the hard disk is mounted in read-only mode. You'll have to remount it read/write before running adduser or nano/vi/etc. This is how I got out of it: http://askubuntu.com/questions/70442/how-do-i-add-myself-back-as-a-sudo-user – Stéphane Nov 26 '11 at 05:16
  • I found I cannot login to root, it says wrong password. But I used the same password, when I was installing ubuntu ... – Jiew Meng Nov 26 '11 at 05:38
  • jiewmeng - I'm in the same boat. I actually recorded my password somewhere else, so the fact that I can't login as root is... not good. – Aaron Newton Jan 26 '12 at 12:53
  • In addition to my last comment, I should add that I'm using an image of Ubuntu 11.10 with VirtualBox under Windows 7. If I revert to a previous snapshot, I can suddenly use sudo again, although I still can't login to root with any of my known passwords. I can confirm that groups shows admin on the good image for my sudo user, but gets removed after the reboot. If you are suffering from the same symptoms, see http://askubuntu.com/questions/70442/how-do-i-add-myself-back-as-a-sudo-user – Aaron Newton Jan 26 '12 at 13:11
  • @AaronNewton Yes, per Stéphane's comment from a couple of months ago, you need to remount the root drive in read/write mode. – Oli Jan 26 '12 at 13:20
  • @Oli thank you for the feedback. Fortunately in my case I had that good snapshot. I restored this, ran "sudo adduser my-user admin" and also set a root password for good measure. After this, I got a clean reboot and I can sudo with my user. – Aaron Newton Jan 26 '12 at 13:33