Monday, September 12, 2016

sudo - No sudoers - what now?


I set up an administrator account for myself when I set up a new Ubuntu system. Somewhere along the line I did something wrong, and my account is now a standard account. I no longer have sudo privileges; when I try to use sudo, it asks for the root password rather than my password. I never set up a root password. Is there a default setting for that password? I can't fix anything without that password, because I need root access to make the fix.


My best guess is that what went wrong may have been due to the following sequence of events: I used addgroup to create a group named family. I used adduser to add an account for my wife, and usermod to put her in the family group. I then used usermod to put myself in the family group. Might I have accidentally removed myself from the sudoers list that way?


I needed two additional pieces of information to solve my problem:



  1. By booting in recovery mode, and selecting "root" from the menu, I could operate as root without knowing root's password, even if logging in as root has been disabled by not giving it a password.

  2. When booting in recovery mode, the root partition defaults to read-only mode. I needed to use mount -rw -o remount / in order to make it writable, before I could make any changes.




I then used usermod to put myself in the family group. Might I have accidentally removed myself from the sudoers list that way?



Yes. In the future, use adduser (username) (group) to add a group membership to a user account.


To fix this, I'd suggest booting via a live CD/USB, mounting the root partition on /mnt, and then:


chroot ./mnt adduser (username) sudo

to get your user account back in the sudo group.


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...