Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I messed up the /etc/sudoers file, now I need to restore it. Booted up the system with an Ubuntu Live CD, installed LVM and mounted the Volume. I'm root and I can't write to the sudoers file in my mounted hd.

I can't change the permission with chmod because system tell me it's a read-only file system.

What should I do?

share|improve this question
by "messed up" you mean "I can't open the file and change it back" on your installation? – Gerep Feb 28 '12 at 13:28
reboot, hold SHIFT, there you can edit the file, I think =), if necessary, I can give you my sudoers file so – Gerep Feb 28 '12 at 13:39
I forced to save it with an error :(. I figure out how to do it, recovery mode, exit from read only file, drop on the root sheel and now I have the write permission :D – Kreker Feb 28 '12 at 13:44
up vote 1 down vote accepted

I figure out how to do it, recovery mode, exit from read only file, drop on the root sheel and now I have the write permission :D

share|improve this answer

Suppose you mounted your install Ubuntu system's root filesystem at /mnt on the transient live CD system, and that the partition is /dev/sda1.

Then remount it readwrite:

sudo mount -o rw,remount /dev/sda1 /mnt
  • If that fails, unmount the filesystem (with umount) and fsck it to find and repair any errors (see also e2fsck).

Then you can edit its sudoers file like this:

sudo visudo -f /mnt/etc/sudoers

Actually, you can edit it as root using whatever mechanism you want. For example, to edit it in such a way as to allow you to introduce errors that break it and prevent sudo from working:

sudo -e /mnt/etc/sudoers

But visudo is better because it won't save your changes to the file if they are syntactically wrong.

By using visudo when editing /etc/sudoers on your installed system (from the installed system), you avoid having to boot into recovery mode, or to a live CD, to fix it.

sudo visudo

If you do break your sudoers file, you can fix it without booting into recovery mode or rebooting, because there is another mechanism besides sudo for becoming root:

pkexec visudo

pkexec is the command-line frontend to PolicyKit. It is generally not present on server systems without a GUI, but it will be present on virtually any Ubuntu system with a GUI (and you do not actually need the GUI to be working to use it, though if there is a GUI it will give you an authentication window rather than authenticating in the terminal itself).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.