1

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?

Eliah Kagan
  • 117,780
Kreker
  • 491
  • by "messed up" you mean "I can't open the file and change it back" on your installation? –  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 –  Feb 28 '12 at 13:39
  • 1
    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

2 Answers2

2

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).

Eliah Kagan
  • 117,780
-1

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
  • 491
  • Exit from what read only file and how? – David Foerster Dec 30 '16 at 16:24
  • I don't remember now but I think there is an entry on the menu when you boot the live cd with "exit from read only mode" or something similar – Kreker Jan 02 '17 at 08:32
  • Hmm… I don't remember seeing that at any point. Maybe they removed it years ago but after you wrote your answer. – David Foerster Jan 02 '17 at 09:12
  • Ok maybe I get it. With "exit from read only file" I was meaning that you you have to remount the file system in write mode with mount -o rw,remount / – Kreker Jan 02 '17 at 09:34