今天誤操作修改了/etc/sudoers的權限,將它的權限改成了777,結果就導致執行所有sudo的命令都報錯。
sudo: /etc/sudoers is world writable
sudo: no valid sudoers sources found, quitting
想重新把它的權限修改回去,但是執行chmod 440 /etc/sudoers后卻發現報錯為:
chmod: Unable to change file mode on /etc/sudoers: Operation not permitted
這就尷尬了,改不回去。
最后通過瘋狂的百度谷歌,找到了一些解決方法,但是有些方法說的太簡單了,還是走了好多冤枉路,現總結如下:
1.在Mac中啟動root 賬戶
https://jingyan.baidu.com/article/49711c619e7620fa441b7ca8.html
2.切換到root用戶,修改 /etc/sudoers的權限
1 #無法使用chmod修改權限 2 demo:Desktop piaoyu.qiu$ ls -la /etc/sudoers 3 -rwxrwxrwx 1 root wheel 1371 8 9 11:28 /etc/sudoers 4 demo:Desktop piaoyu.qiu$ chmod 440 /etc/sudoers 5 chmod: Unable to change file mode on /etc/sudoers: Operation not permitted 6 7 #切換到root用戶 8 demo:Desktop piaoyu.qiu$ su 9 Password:你自己設置的密碼 10 sh-3.2# ls -l /etc/sudoers 11 -rwxrwxrwx 1 root wheel 1371 8 9 11:28 /etc/sudoers 12 sh-3.2# chmod 0440 /etc/sudoers 13 sh-3.2# ls -l /etc/sudoers 14 -r--r----- 1 root wheel 1371 8 9 11:28 /etc/sudoers 15 sh-3.2# exit
完美解決問題,最后說一句Mac好煩人!!