0

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.

3 Answers 3

3

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
4
  • 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. Jan 21, 2012 at 12:37
  • askubuntu.com/questions/24006/…
    – Thermionix
    Jan 21, 2012 at 12:42
  • 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. Jan 21, 2012 at 15:15
  • Using the live CD to edit /etc/group worked. Jan 21, 2012 at 23:26
1

I had the exact same issue on Ubuntu 16.04 recently. I added my user into a group without the -a option and got removed from all other groups including sudo, and hence lost the root permissions to add it back.

The solutions I found for fixing this needed me to boot into recovery mode. I couldn't do this because I had only a Bluetooth keyboard, which doesn't work until I login.

I found the procedure for solving this problem in the answer to another question here: https://askubuntu.com/a/435347/841719. Rephrasing with slight edit for the context

  1. Boot to the Live media. You can use an Ubuntu USB.
  2. Open a terminal
  3. Find out the device name for your primary disk (root partition '/') using

    sudo fdisk -l
    
  4. Mount this somewhere using read/write mode, so we can use it (* change the disk from sda1 to your drive's name):

    sudo mount -o rw /dev/sda1 /mnt
    
  5. CD into the mounted drive using cd /mnt
  6. Edit the groups file using

    sudo gedit /etc/group 
    

    Add your username to important groups like sudo, admin etc. You can add to all the other groups you were removed from later once you gain the sudo Make sure you follow the formatting of the groups file.
    format example:

    group-name:x:group-number:user1,user2
    admin:x:110:username
    
  7. Save the file and exit

  8. Get out of /mnt using cd /
  9. Unmount the drive using umount /mnt (it threw up an error for me so I ignored this step)
  10. Shutdown the PC, remove the bootable live USB and boot into the native Ubuntu.
  11. Now you should have the sudo privilege restored. Check by typing

    sudo df
    
0

Similar, or possible the same issue: For some reason, creating a USB live mint (in my case mate+cinnamon) does not allow you to sudo (and therefore you cannot install).

What is crazy is that you CAN su in a non-graphical console!

To solve this:

  • open a terminal and type passwd
  • give a password for the mint
  • press Ctrl+Alt+F1 to go to a non-graphical console
  • login as mint with your password
  • type su to become root
  • type echo "mint ALL=(ALL:ALL) ALL" >> /etc/sudoers (with the quotes)
3
  • 1
    I would recommend editing sudoers with visudo instead.
    – slhck
    May 15, 2012 at 7:53
  • 1
    @slhck in that case it doesn't matter. It is important not to use sudo when editing sudoers. Echo will edit it instantly.
    – enedil
    Mar 4, 2014 at 18:54
  • Good points. For details why: unix.stackexchange.com/questions/27594/…
    – ntg
    Mar 31, 2016 at 13:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .