我发现,为了在多个服务器之间轻松复制此行为,最直接的方法是:
sudo visudo
更改此行:
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
到这行:
# Members of the admin group may gain root privileges
%admin ALL=(ALL) NOPASSWD:ALL
并移动在这一行:
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
您现在应该拥有:
# 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
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) NOPASSWD:ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
然后对于每个需要使用密码进行 sudo访问的用户:
sudo adduser <user> sudo
对于需要sudo访问而无需密码的每个用户:
sudo adduser <user> admin
最后,运行此命令:
sudo service sudo restart
就是这样!
编辑:您可能必须添加管理员组,因为我默认情况下不存在该管理员组。
sudo groupadd admin
您还可以通过以下命令将默认的AWS ubuntu
用户添加到admin
组中:
sudo usermod ubuntu -g admin
注意:如@hata所述,您可能需要使用adm
admin组名,具体取决于所使用的Ubuntu版本。