sudo 不要求输入密码

Rah*_*ara 15 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
Run Code Online (Sandbox Code Playgroud)

JB.*_*ca. 15

使用该命令,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
Run Code Online (Sandbox Code Playgroud)

您当前的用户可能是特权组的成员,该组使他能够在没有密码的情况下输入 sudo 命令。在这个例子中,adminsudo组的成员可以使用 sudo 发出任何命令,但会提示输入密码;nopwd不会提示组成员输入密码。

请注意,声明顺序与属于多个组的用户相关。不经意间,最后一个匹配组获胜!

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

%users  ALL=NOPASSWD: /sbin/reboot, PASSWD: /usr/bin/apt-get
Run Code Online (Sandbox Code Playgroud)

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