![sudo 命令没有密码提示](https://linux22.com/image/819950/sudo%20%E5%91%BD%E4%BB%A4%E6%B2%A1%E6%9C%89%E5%AF%86%E7%A0%81%E6%8F%90%E7%A4%BA.png)
每当我发出命令 sudo apt-get install**它不需要输入密码,我的管理员用户也不需要。
如何使其提示输入密码?
我的 sudoer:
ubuntu:~$ sudo cat /etc/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 secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root 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
ALL ALL=(ALL) NOPASSWD:ALL
答案1
/etc/sudoers
使用编辑sudo visudo
,并删除最后一行:
ALL ALL=(ALL) NOPASSWD:ALL
(顺便说一下,请注意文件末尾的这一行是不是首选方式sudo
不是提示输入密码,对于那些想要这样做的人。)
答案2
使用此命令来查找问题的根源:
sudo grep -HRn NOPASSWD /etc/sudoers.d/
就我而言:
/etc/sudoers.d/50_stack_sh:1:username ALL=(root) NOPASSWD:ALL
用#注释该行并关闭终端。
答案3
我认为最好在文件末尾添加“管理员用户”,因为管理员不必在终端的每个命令中都输入密码,并且其他用户也不允许这样做:
# 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 secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root 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
# ALL ALL=(ALL) NOPASSWD:ALL
(user here) ALL=(ALL) NOPASSWD:ALL