Let it boot normally, until it asks for your username & password in the console.In Ubuntu 16.04 running on a VirtualBox (shouldn't make a difference), the above methods didn't work for me (invalid row in the end of the file). But I'm sure losing one shell session is much better than losing your server! (According to the manpage, this is the normal behavior: When its services are no longer needed, the process can be killed.) NOTE: Using this approach, after running your command, probably your access to the shell will be gone. Then, you can overwrite your sudoers file: pkttyagent -p $(echo $$) | pkexec cp ~/sudoers /etc/sudoers If you want to recover the default /etc/sudoers, you can use this gist to copy the default configurations, putting it in a non-root accessed place (e.g. If you want to remove a corrupted file in sudoers.d directory, use this: pkttyagent -p $(echo $$) | pkexec rm /etc/sudoers.d/FILENAME In this situation, using pkttyagent can be helpful. When this happens to a non-GUI system (your production server, maybe) the pkexec fails with this error message: polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error.Failed: No session for cookieĮrror executing command as another user: Not authorized (which will prevent you from saving a sudoers file with incorrect syntax). Or, even better, you can edit it with sudo visudo -f /mnt/etc/sudoers Then you can edit the installed system's sudoers file with sudo nano -w /mnt/etc/sudoers. Then you could mount it with sudo mount /dev/sda1 /mnt. Suppose the installed Ubuntu system's root filesystem is on /dev/sda1. You can do this by running sudo parted -l to view your partitions-there is probably just one ext4 partition, and that's the root filesystem. If that doesn't work-for example, if there are no users authorized to run programs as root via PolicyKit-then boot from an Ubuntu live CD (like the CD you probably used to install Ubuntu) and mount the filesystem for the installed system. (If there is more than one user account on the system authorized to run programs as root with PolicyKit, then for any of those actions, you'll be asked to select which one you want to use, before being asked for your password.) Generally speaking, any non-graphical command you'd run with sudo can be run with pkexec instead. If you have a related situation where you have to perform additional system administration commands as root to fix the problem (also uncommon in this circumstance, but common in others), you can start an interactive root shell with pkexec bash. If you need to edit one of the configuration files in /etc/sudoers.d (which is uncommon in this situation, but possible), use pkexec visudo -f /etc/sudoers.d/ filename. If you have physical access to the machine, SSH is unnecessary just open a Terminal window and run that pkexec command.Īssuming you (or some other user) are authorized to run programs as root with PolicyKit, you can enter your password, and then it will run visudo as root, and you can fix your /etc/sudoers. To do this via SSH, log in to the machine and run the command pkexec visudo. On a modern Ubuntu system (and many other GNU/Linux distributions), fixing a corrupted sudoers file is actually quite easy, and doesn't require rebooting, using a live CD, or physical access to the machine.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |