0

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.
karel
  • 114,770
  • If you know your root password then you can add yourself in sudoers using visudo. – Rahul Nov 23 '16 at 05:44
  • You can try to boot into a root shell and add yourself back in sudo. – sourav c. Nov 23 '16 at 05:51
  • I'm the one who installed Ubuntu on this machine, and I didn't set up a root passwd on it. The only way I'd be able to follow either of those suggestions would be if the root password has a default value. If so, could someone tell me what it is? – James Kuyper Nov 23 '16 at 14:26
  • I successfully booted from the same USB drive I used for the installation. It automatically tried to mount the root partition (/dev/sdb1) as /media/ubuntu/Ubuntu 16.04 LTS amd64. That attempt failed because /dev/sdb1 is write-protected. I got the same error message when I tried to mount it manually. How can I undo the write protection? – James Kuyper Nov 23 '16 at 14:59
  • I've got the password for my account - the problem is that it is no longer the administrative account, and neither is any other account on the machine. sudo keeps asking me for the "root" password, and giving it my own password doesn't work anymore. Can I use this method to unlock the root account and give it a known password? If so, that would solve my problem. However, see the comment I'm posting in response to DepressedDaniel's answer. – James Kuyper Nov 23 '16 at 18:57

1 Answers1

0

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.

  • The reason I couldn't get this to work is because the root partition was write-protected. The link that Karel provided mentions usingmount -rw -o remount / to remount with write permissions. – James Kuyper Nov 23 '16 at 18:50
  • If I can use that command while following DepressedDaniel's instructions, I wouldn't need to unlock the root account, which I didn't really want to do in the first place. I won't be able to try this out for at least another 6 hours, so I'm posting this response right now, in the hopes that someone will tell me whether it should work (and if not, what I should do instead). – James Kuyper Nov 23 '16 at 19:04
  • @JamesKuyper I've never encountered the write protection problem. It could be that your hardware is no longer allowing writes (e.g., due to SSD running out of spare blocks). One could try hdparm -r0 /dev/sdb in case it is a setting. – DepressedDaniel Nov 25 '16 at 01:53
  • I don't think it had anything to doe with a lack of spare blocks. "mount -rw -o remount /" was sufficient to solve the problem. – James Kuyper Nov 25 '16 at 03:24