我想为系统上的一个特定用户覆盖 env_keep。(对于所有用户 - 工作没有问题)。
我读了 man sudo 和 man sudoers,用谷歌搜索了一下——但我还是不明白为什么这个结构不起作用
Defaults:www-data env_keep+="SSH_AUTH_SOCK"
(也有一个选项+=
,但只是简单=
)
我错过了一些东西,但是什么?
这是我的/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
# 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
这是我的/etc/sudoers.d/www-data
:
Defaults:www-data env_keep="SSH_AUTH_SOCK"
我将其作为标准检查:我通过 SSH 登录,查看有一个变量echo $SSH_AUTH_SOCK
,然后我更改 sudoers 并尝试检查:
sudo -u www-data -s /bin/bash -c 'echo $SSH_AUTH_SOCK'
sudo -u yetanotheruser -s /bin/bash -c 'echo $SSH_AUTH_SOCK'
我希望在第一种情况下看到一个非空变量,在第二种情况下看到一个空变量。正如我所说,它可以工作,如果我将 global 更改Defaults env_reset
为Defaults env_keep
(或 set Defaults env_keep+="SSH_AUTH_SOCK"
),尽管根据文档它应该适用于个人用户,从评论来看。
如果对理解机制很重要,该系统在 debian11 下。用户正是 www-data,即 无壳。