系統環境:ubuntu 12.04
狀況:
因為修改了/etc/sudoers以及相關權限,導致sudo無法使用,恰好Ubuntu的root密碼沒有設置。
錯誤如下:
~$ sudo sudo: >>> /etc/sudoers:syntax error 在行 21 附近<<< sudo: /etc/sudoers 中第 21 行附近有解析錯誤 sudo: 沒有找到有效的 sudoers 資源,退出 sudo: 無法初始化策略插件
於是,只能進去單用戶模式(擁有root權力)去修改,在Ubuntu下,開機時長按shift出現各種模式,選擇第二個recovery mode,按e進去編輯。
解決方法:
1、重啟ubuntu,啟動時按Esc或Shift鍵,可以看到引導選項;
2、在引導選項中選擇Recovery模式的那一項來引導;
3、進入Recovery Menu頁面,選擇root,也就是進入試用root用戶進行系統恢復,在這里可以執行超級用戶的權限的操作,回車后可以看到熟悉的 root@user ~# 命令提示符;
4、設置或者撤銷/etc/sudoers文件的權限,也可以將該文件改回到發生錯誤之前的狀態。
chmod 666 /dev/null mount -o remount rw / vi /etc/sudoers 恢復本文件內容並存盤
5、退出Recovery模式,重新啟動ubuntu。
PS:當然也可以用ubuntu光盤引導系統,然后mount相應的磁盤,然后修改/etc/sudoers文件,進入系統,就可以正常啟動了(linux使用熟練的話不妨一試)。
# /etc/sudoers # # This file MUST be edited with the 'visudo' command as root. # # See the man page for details on how to write a sudoers file. # Defaults env_reset # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL) ALL # Allow members of group sudo to execute any command after they have # provided their password # (Note that later entries override this, so you might need to move # it further down) %sudo ALL=(ALL) ALL # #includedir /etc/sudoers.d # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL