sudo不再要求输入密码了

我没注意到它,但是因为我输入了使用sudo priviledges的密码已经有一段时间了。

这是我的/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 mail_badpass 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 %jupiter ALL=NOPASSWD: /usr/lib/jupiter/scripts/bluetooth, /usr/lib/jupiter/scripts/camera, /usr/lib/jupiter/scripts/cpu-control, /usr/lib/jupiter/scripts/resolutions, /usr/lib/jupiter/scripts/rotate, /usr/lib/jupiter/scripts/touchpad, /usr/lib/jupiter/scripts/vga-out, /usr/lib/jupiter/scripts/wifi 

这让我很担心,因为任何脚本现在都可以运行而无需输入密码。

我看过以下问题,但它们似乎与这篇文章无关:

  • sudo不要求密码
  • 没有密码提示sudo

如何使sudo 始终提示我输入密码(在/etc/sudoers文件中给出超时持续时间?

PS:我的.bash_aliases中设置了一些使用sudo命令的别名,但我希望这与密码提示无关,或者是吗?

你的最后一行是罪魁祸首。 我不知道为什么,也许这是一个错误,或者我不知道所有的Linux规则。

你应该考虑以下几点:

 # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. 

所以删除最后一行并将其放在/etc/sudoers.d/sudo-jupiter 。 现在将/etc/sudoers权限恢复为ux并重新启动系统

我发现使用devbuack使用 on Ubuntu 12.10 安装grizzly openstack会创建一个文件/etc/sudoers.d/50_stack_sh其内容如下:

 jobin ALL=(root) NOPASSWD:ALL Defaults:jobin secure_path=/sbin:/usr/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin 

这删除了所有命令的密码提示,我可以以root身份运行这些命令,因此我从未提示输入密码。

为了解决这个问题,我删除了/etc/sudoers.d/50_stack_sh文件(我不再需要openstack了)。 对于那些需要openstack和密码提示的用户,请将文件/etc/sudoers.d/50_stack_sh的内容更改为:

  ALL=(root) ALL Defaults: secure_path=/sbin:/usr/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin 

用需要密码提示的帐户的用户名替换


这个答案是基于用户neckTwi的回答和Unix和Linux上有关/ etc / sudoers文件语法的问题 。


注意 :我在ask.openstack.org上提出了一个问题,要求澄清上面提到的方法 ,希望我们尽快得到答案:)