系統環境:ubuntu 12.04linux
情況:ubuntu
由於修改了/etc/sudoers以及相關權限,致使sudo沒法使用,剛好Ubuntu的root密碼沒有設置。ide
錯誤以下:this
~$ sudo sudo: >>> /etc/sudoers:syntax error 在行 21 附近<<< sudo: /etc/sudoers 中第 21 行附近有解析錯誤 sudo: 沒有找到有效的 sudoers 資源,退出 sudo: 沒法初始化策略插件
因而,只能進去單用戶模式(擁有root權力)去修改,在Ubuntu下,開機時長按shift出現各類模式,選擇第二個recovery mode,按e進去編輯。spa
解決方法:插件
一、重啓ubuntu,啓動時按Esc或Shift鍵,能夠看到引導選項;code
二、在引導選項中選擇Recovery模式的那一項來引導;blog
三、進入Recovery Menu頁面,選擇root,也就是進入試用root用戶進行系統恢復,在這裏能夠執行超級用戶的權限的操做,回車後能夠看到熟悉的 root@user ~# 命令提示符;ci
四、設置或者撤銷/etc/sudoers文件的權限,也能夠將該文件改回到發生錯誤以前的狀態。資源
chmod 666 /dev/null mount -o remount rw / vi /etc/sudoers 恢復本文件內容並存盤
五、退出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