How to get user back to sudo group if root account is not active or password is unknown under Ubuntu Linux
Preamble
As you probably know in Ubuntu 11.10 there is no graphical applet to add/remove users to/from groups and instead of this you have to use terminal and short command to manage them.
Unfortunately it is very easy to make a mistake and be removed from all the other groups.
The usual mistake is missing -a flag in the command below which will add you to the vboxsf group but... it will remove you from all the others!
sudo usermod -G vboxsf fred
If you want to be added to the vboxsf group but not removed from the other the command should looks like this:
sudo usermod -a -G vboxsf fred
or simply:
sudo usermod -aG vboxsf fred
If this happened, you are in the right place and continue to read.
Solution
It is not that hard to put everything back like it was before as your groups settings should be automatically saved to the backup file (/etc/group-).
Do the steps below and you will be a happy Linux user again.
-
First we need to start system in the recovery mode:
- Restart it -> when you see the BIOS screen press shift button and hold it until you see the grub menu
- Select recovery mode and press enter
- When Recovery Menu will pop up -> go arrow down to Drop to root shell prompt section -> and hit enter
-
You should see command prompt similar to the below:
root@hostname:~# _
-
Enter the following command to remount file system from RO to RW:
mount -n -o remount, rw /
-
It is always good idea to make backup of the file we want to change:
cp /etc/group /etc/group.bak
-
And then overwrite existing group file with the previous version:
cp /etc/group- /etc/group
-
Check if your user is definitely assigned to sudo group:
cat /etc/group |grep sudo
-
If you see the line similar to the below everything seems to be ok and go to step no. 12:
root@hostname:~# cat /etc/group |grep sudo sudo:x:27:fred
-
If NOT -> edit the group file (you can use any file editor you like):
editor /etc/group
- Find the line which starts with sudo:x: -> and add your username at the end of this line
- Save file and exit editor by pressing Ctrl+X ->then letter Y -> and enter
-
Exit recovery mode by writing command:
exit
- And finally exit Recovery Menu by selecting Resume normal boot and pressing enter
After these steps your system should starts normally and your user should be assigned to the sudo group again.
Document version: 1.2
Last modified on:
Comments