Linux下sudo命令⽆法使⽤及报sudoers.d下某⽂件语法错误Linux下sudo命令⽆法使⽤及报sudoers.d下某⽂件语法错误
在这种情况下我们是往往进⼊不到root模式下的
问题来源:添加⽤户的时候重复添加等导致。
sudoers⽂件错误
pkexec visudo命令打开sudoers⽂件
修改该⽂件(此处展⽰⼀份⽆错配置)
#
linux所有命令都无法使用# 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*"查看是否还有与该⽤户相关的⽂件

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。