Repair sudoers file on Ubuntu 12.04 LTS

Not really a network blogpost, but during the installation of Smokeping I somehow managed to damage my sudoers file. As a result I was not able to login to my Ubuntu machine. Because of the lack of a snapshot, the ubuntu machine is a virtualmachine, I could not just jump back in time and start over. I almost started installing the machine all over again, but then I found the solution by using google.

Here the steps to repair the sudoers file on Ubuntu Linux.
  • Restart your machine and start your machine in “recovery mode”
  • Choose to login as “root”
  • The file-system is mounted as read-only, to mount it in read-write mode use the following command: “mount -o rw, remount /”
  • Now copy the sudoers file to a backup file “sudo cp /etc/sudoers /etc/sudoers.backup/”
  • Create a new sudoers file: “sudo nano /etc/sudoers” and copy the following in to the file:

# This file MUST be edited with the ‘visudo’ command as root.
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
# See the man page for details on how to write a sudoers file.
Defaults env_reset
Defaults secure_path=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”
# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command

# See sudoers(5) for more information on “#include” directives:

#includedir /etc/sudoers.d

  • Now close and save the file by using “ctrl + X” and restart the machine by “sudo shutdown -r now”

One Response to Repair sudoers file on Ubuntu 12.04 LTS

  1. locked out also says:

    thanks for the post. small typo in your command. I needed to use:

    mount -o remount, rw /

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: