練習安裝odoo的時候,創建了一個odoo用戶,想把它賦予sudo權限,然而,編輯的時候不留意,改壞了,導致sudo無法使用,無法編輯sudoers文件修改回來。
總提示如下信息:
>>> /etc/sudoers: syntax error near line 22 <<< sudo: parse error in /etc/sudoers near line 22 sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin
網上說可以使用下面的命令來編輯sudoers文件
pkexec visudo
然鵝,又出現另一個錯誤信息:
==== AUTHENTICATING FOR org.freedesktop.policykit.exec === Authentication is needed to run `/usr/sbin/visudo' as the super user Authenticating as: ubuntu,,, (ubuntu) Password: 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.
尋尋覓覓,終於找到一個神奇的方法:遠程的話開兩個ssh終端,能直接操作物理機的話使用ctrl+alt+F2 創建第二個終端窗口【使用ctrl+alt+F1=》tty1;ctrl+alt+F2=》tty2對窗口進行切換】,兩個終端,都用ubuntu用戶登錄。
對tty1終端:輸入 echo $$
//獲取pid
切換到tty2:輸入 pkttyagent --process 獲取的pid值 ;此時該tty2終端會卡住
切到tty1:輸入 pkexec visudo ;此時tty1也會卡住
切到tty2:會看到要求輸入密碼,對應輸入
切回到tty1:發現已經進入了visudo編輯界面,修改出錯的sudoers,保存。
修改完成,發現就可以繼續使用sudo命令了。
PS:
一般對/etc/sudoers文件進行操作,建議使用visudo命令. 注意:不要直接使用 vi,直接使用vi不會對文件新加的做相關驗證,這可能導致該文件無法正確解析.最終導致sudo命令不能使用,也不能切換使用root用戶等一系列問題..
https://blog.csdn.net/caijiapeng0102/article/details/84848473
https://sanyecao2314.iteye.com/blog/2278016