Linux下sudo命令無法使用及報sudoers.d下某文件語法錯誤
在這種情況下 我們是往往進入不到root模式下的
問題來源:添加用戶的時候重復添加等導致。
sudoers文件錯誤
-
pkexec visudo
命令打開sudoers文件 -
修改該文件(此處展示一份無錯配置)
# # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL stack ALL=(ALL) NOPASSWD: ALL #dengschoo ALL=(ALL:ALL) ALL # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d
-
ESC: Ctrl + X
保存退出(可能要按兩次 多看提示) -
再嘗試sudo命令等 檢查是否還有其它問題
sudoers.d目錄下某個文件報錯
這種情況下sudoers文件是沒有問題的 就需要先把
sudoers.d
目錄從sudoers
文件中移除
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
stack ALL=(ALL) NOPASSWD: ALL
#dengschoo ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#就是這句 包含了該目錄下的其他用戶的權限 把它注釋
#includedir /etc/sudoers.d
#includedir /etc/sudoers.d
=> ##includedir /etc/sudoers.d
然后就可以正常使用sudo命令了 就可以切換到root用戶 然后刪除或者修改出問題的文件了。
修改完成后別忘記重新 把剛才的注釋改回來 為了不影響以后其它操作。
完全刪除用戶
userdel -r username
find / -name "*haha*"
查看是否還有與該用戶相關的文件