Broken /etc/sudoers file - how to recover after access loss

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
gilthanaz
Site Admin
Posts: 444
Joined: Fri Aug 29, 2003 9:29 pm
Contact:

Broken /etc/sudoers file - how to recover after access loss

Post by gilthanaz »

[Problem]
Working on an Ubuntu Server 14.04.3: After a modification to the /etc/sudoers file, I actually accidently broke it. Unfortunately before i could undo my changes, i lost the SSH connection and thus my shell with elevated access. After logging back into the machine, i could not execute the sudo command anymore, thus i also could not modify the /etc/sudoers file anymore to fix it! Daaaarn!

>>> /etc/sudoers: syntax error near line 32 <<<
sudo: parse error in /etc/sudoers near line 32
sudo: no valid sudoers sources found, quitting


[Solution]
As physical access was no option in this case, the solution to fix this is to use pfexec and the visudo command. As long as there is at least one user in the admin group that you know the password of, you can use:

Code: Select all

pkexec visudo
This will enable you to chose and authenticate as a admin user and modify the sudoers file back into a working state!
Post Reply