21

I have one admin account and recently I have accidentally added myself to a single group (usermod -G without -a).

So, I am not in the sudoers file any more. However, it is not possible to log in to root by default on Ubuntu. Do I reset the password for root during the boot process?

0
36

No need to reset root password (well, technically, Ubuntu's root does not even have a password). Do this:

  • Reboot your PC

  • In Grub's OS selection screen, choose "Ubuntu xxxx - recovery mode"

  • Now you have a console with root privileges. Add your user back to sudo group:

      usermod -a -G sudo youruser
    

The shell might reply that it cannot do it because the file system in mounted in read-only. To remount your fs in read-write: mount -o remount,rw /

  • That will be enough for sudo. But its suggested you also re-add yourself to other default administrative groups. You can reboot, logon normally and use GUI:

Menu > Administration > Users and Groups > Advanced Settings > User Privileges or Account Type (Change...) > Administrative

  • Or use this command:

      sudo usermod -a -G adm,cdrom,plugdev,lpadmin,sambashare youruser
    

Notes:

  • The sudo group used to be the admin group prior to Ubuntu 12.04. If you're on anything older, replace the group sudo with the group admin in the above commands.
  • Starting from Ubuntu 20.04, the fuse group does not exist anymore. It allowed regular users to access /dev/fuse using fusemount, i.e., to mount FUSE filesystems. But since Debian 8 /dev/fuse is already world-writeable by default.

Important Note: The default set of groups for what is considered an "Administrator" role changes over time, as some groups become obsolete or irrelevant (such as tape or floppy), are removed, renamed or re-organized, or are created in your system only when related packages are installed (sambashare, virtualbox, www_data). So in a few years adm, cdrom or lpadmin might not exist (that is, if they still do!).

Besides, some features that currently use groups for filesystem-based permissions might change to another access permission mechanism, such as udev, PAM, AppArmor, SELinux, etc.

So the only way to get an updated list of groups is... to check your current system! Create a new temporary Administrator user using the GUI, or do a fresh install in a VM, and see which groups the user is assigned to by default.

6
  • That's what I figured out myself. Thanks anyways :)
    – m33lky
    Aug 31 '11 at 5:49
  • 2
    Glad you found out. And hope you didnt "reset" root's password while trying. In Ubuntu root is a disabled account (=no password), for a good reason. Keep it that way. You will still be able to use sudo, sudo su, recovery mode, etc. Disabling root's password only mean you can not login as root in a login shell, which is a very good security measure.
    – MestreLion
    Aug 31 '11 at 5:57
  • Hypothetically ... What if one had disabled GRUB recovery mode by uncommenting GRUB_DISABLE_RECOVERY="true" in /etc/default/grub. What would one do?
    – daka
    May 26 '16 at 22:18
  • 1
    @sudoman: boot using a CD/USB live session, mount the original root partition, edit its /etc/default/grub(or directly the config files at /boot/grub) and update/reinstall grub. Basically the same procedures as if you had lost grub as the boot manager (when installing windows, for example)
    – MestreLion
    Jun 1 '16 at 10:05
  • On Mint 20, I get usermod: group 'fuse' does not exist, so I just left it out. Apr 10 at 13:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.