sudo不要求密码

每当我发出命令sudo apt-get install foo它都不会要求输入密码。 是因为用户群?

如何让它提示输入密码?

编辑:我的sudoers文件

 apple@Ascension:~$ 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 # 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 #includedir /etc/sudoers.d ALL ALL=(ALL) NOPASSWD:ALL ALL ALL=(ALL) NOPASSWD:ALL ALL ALL=(ALL) NOPASSWD:ALL 

使用命令sudo visudo您可以查看和编辑sudo配置,例如:

 # 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 # Group without password %nopwd ALL=NOPASSWD: ALL 

您当前的用户可能是特权组的成员,使他无需密码即可输入sudo命令。 在此示例中, adminsudo组的成员可以使用sudo发出任何命令,但会提示输入密码; nopwd组的成员不会被提示输入密码。

请注意,声明顺序与属于多个组的用户相关。

为了需要密码,您可以在文件/etc/sudoers添加PASSWD: /usr/bin/apt-get命令规范; 请注意,您可能希望允许没有密码的特定命令,并使用密码保留每个其他命令。 明确请求apt-get密码的示例:

 %users ALL=NOPASSWD: /sbin/reboot, PASSWD: /usr/bin/apt-get 

请注意,您可以使用比我的第一个示例( doc ubuntu fr )( doc ubuntu en )中的所有命令更精细的粒度来个性化sudo。