作死修改/etc/sudoers导致无法使用sudo命令。

每次使用sudo输入密码后显示:

/etc/sudoers: syntax error near line 26
sudo: parse error in /etc/sudoers near line 26
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

使用su命令切换root用户

You are required to change your password immediately (root enforced)
Changing password for root.
(current) UNIX password:
su: Authentication token manipulation error

使用pkexec命令

polkit-agent-helper-1: error response to PolicyKit daemon:
GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie
==== AUTHENTICATION FAILED ===
Error executing command as another user: Not authorized
This incident has been reported.

解决方法:

  1. 登录Digitalocean,点击"Recovery",然后关闭VPS;
  2. 选中"Boot from Recovery ISO"后开机重启VPS;
  3. 点击"Console"进入VPS终端,会有如下6个选项:

    Your are strongly encouraged to use SSH keys. To import your SSH
    public keys: From Github: ssh-import-id gh:<Github user name>

    From Launchpad.net: ssh-import-id lp:<launchpad user name>

    1. Mount your Disk Image [Not Mounted]
    2. Check Filesystem
    3. Reset Droplet Root Password
    4. Configure Keyboard
    5. Attempt to 'chroot' into installed system
    6. Interactive Shell [/bin/bash] Choose (1-6) and press Enter to continue.
  4. 先输入1回车挂裁硬盘,然后输入6运行bash
  5. 输入命令nano /mnt/etc/sudoers修改文件,修改完毕后退出即可;
  6. 关闭VPS,选择"Boot from Hard Drive",开机后就可以正常使用sudo命令了。

DigitalOcean Recovery