How to restore sudo privilege with Linux live CD?

10,713

You'll have to boot into recovery mode to gain root (system-wide) access in order to repair

If you have a single-boot (Ubuntu is the only operating system on your computer), to get the boot menu to show, you have to hold down the Shift key during bootup.

From the boot menu, select recovery mode

After you select recovery mode and wait for all the boot-up processes to finish, you'll be presented with a few options. In this case, you want the Drop to root shell prompt option.

/etc/group is the file that defines the groups on the system

You can then use adduser username admin to readd your user to the admin group.

Alternatively you can use the vigr command to edit the /etc/group file safely

format example;

group-name:x:group-number:user1,user2
admin:x:110:username
Share:
10,713

Related videos on Youtube

Mike Rowave
Author by

Mike Rowave

Updated on September 18, 2022

Comments

  • Mike Rowave
    Mike Rowave over 1 year

    I'm running Linux Mint 11 and I lost the privilege to use sudo, apparently the result of accidentally removing myself from the admin group.

    When I use the groups command to list the groups I'm in, it only shows my user ID and vboxusers. I think I mistakenly used usermod instead of useradd to put my ID in the vboxusers group, so I got removed from all other groups.

    Solutions I found on the web (like this: http://www.psychocats.net/ubuntu/fixsudo) describe choosing recovery mode in the GRUB menu, getting a root prompt and using that to add my user back to the group. But when I do that it asks for the root password, which I don't know because Linux Mint and other Ubuntu-based distributions don't allow you to see or set the root password during installation.

    I have Linux live CDs so I can gain root privileges that way, but that won't enable me to manipulate users in the Mint installation via the command line. However, I can use that to edit any file, so which file should I edit and how should I edit it so I can regain admin (and consequently sudo) privileges?

    My ID is still in the sudoers file, as shown with cat /media/mint/etc/sudoers when running the live CD.

  • Mike Rowave
    Mike Rowave over 12 years
    As I mentioned above, the "Drop to root shell" doesn't work because it asks for the root password. But I'll try to edit the /etc/group as you described.
  • Thermionix
    Thermionix over 12 years
  • Mike Rowave
    Mike Rowave over 12 years
    Thermionix - after selecting the root prompt option on that menu, it says Enter root password or press Ctrl-D to continue. Ctrl-D simply returns to the same menu. Without knowing the root password, the recovery mode won't let me do anything.
  • Mike Rowave
    Mike Rowave over 12 years
    Using the live CD to edit /etc/group worked.
  • slhck
    slhck almost 12 years
    I would recommend editing sudoers with visudo instead.
  • enedil
    enedil about 10 years
    @slhck in that case it doesn't matter. It is important not to use sudo when editing sudoers. Echo will edit it instantly.
  • ntg
    ntg about 8 years
    Good points. For details why: unix.stackexchange.com/questions/27594/…