“Super” screwup

Recently I was checking the possibility of having shared folders between different users on my laptop, some common way to drop files into a folder and let the other user pick them up for use. The idea was simple enough and I also found sufficient details on forums explaining how this can be done. But I must have screwed up the commands or permissions on the files somehow.

“sudo visudo” is the culprit command I think. Because after messing with the sudoers file, I have managed to remove my only account from the sudoers list. So now there is no Admin account on my laptop and no other user with “sudo” access.

koolksp@koolksp-3000-N100:~$ sudo visudo
[sudo] password for koolksp:
koolksp is not in the sudoers file. This incident will be reported.
koolksp@koolksp-3000-N100:~$

This is affecting my users permissions to install/remove any software, change any system level settings and so on. So much so, that without root access I cannot add myself to the sudoers list. I dont think I am aware of the root password as well, because I had setup my user as the only one on the system with root access and now ironically that access is gone.

koolksp@koolksp-3000-N100:~$ su
Password:
su: Authentication failure
koolksp@koolksp-3000-N100:~$

Apparently I will need sudo access to restore my sudo access! Pondering on options to get out of this soup. “super” screw up indeed.

SOLVED : It took some time scanning online forums, but finally got an answer to this.

You cant execute sudo without having your username in the sudoers list. Thats a given. Which means if you dont have sudo rights and are not root user of the system, there’s not much you can do.

But the solution I stumbled upon is to use a live cd to boot into such a system and attempt to edit /etc/sudoers file as root and add the required username to it.

The way this works is, the root user of the live cd doesnt have any password set. So once booted into my laptop with elementary os’s live cd, I could change user to root by using sudo -i

With this, I could mount my host’s root directory and edit the /etc/sudoers file as root user. Mind you, attempting to edit /etc/sudoers using visudo will only change the list for the live session and isn’t what we are looking for. The correct file to edit is /<mount-point>/etc/sudoers. In my case, I found it under /media/

Added the following line at the end of the file to grant my user sudo rights.

koolksp ALL=(ALL) ALL

This is also a good oportunity to have another user added here for contingency sake.

Saved the file and rebooted the machine. Sure enough I was able to execute sudo command, but gui applications like the synaptic manager or the settings tool weren’t able to log me in, to change any settings or install software.

Apparent reason for this was that my user koolksp was still not part of the “sudo” group, which is required to grant access when using gui apps.

I could change this by command sudo usermod -G sudo koolksp which adds a sudo group to my secondary groups list. Verify this by issuing groups command.

Note that on the ubuntu platform and its derivatives, the admin group no longer exists. It has been moved to sudo now.

With the last change, I was now part of the sudoers list as well as the sudo group, which allows me to make system wide changes and install/remove softwares. After some effort, my sudo priviledges are back on track.

As a caution, I am adding another user from my system to the sudo group, so in case I find myself in this soup again, the other user with intact sudo access can rescue the situation.

Leave a comment