以另一个用户身份执行sudo -l命令

3

大家好,我正在尝试列出一个用户在root权限下可以访问的所有sudo命令。显然我们可以在sudoers文件中看到,但如果有很多用户/命令别名,就会变得困难。

我正在尝试以root身份为另一个用户执行sudo -l。

我已经尝试使用-u选项。

sudo -u testuser -l 

抛出命令使用信息。
sudo -u testuser sudo -l

提示输入testuser的密码(由于我是以root用户身份操作,所以不需要密码提示)

su - testuser -c 'sudo -l' 

给我以下错误信息:
sudo: no tty present and no askpass program specified

请告诉我如何处理这个问题。

1个回答

1
根据man sudo的说明:
 -U user, --other-user=user
             Used in conjunction with the -l option to list the privileges
             for user instead of for the invoking user.  The security pol-
             icy may restrict listing other users' privileges.  The
             sudoers policy only allows root or a user with the ALL privi-
             lege on the current host to use this option.

您正在使用-u,这是完全不同的东西:

 -u user, --user=user
             Run the command as a user other than the default target user
             (usually root ). The user may be either a user name or a
             numeric user ID (UID) prefixed with the '#' character etc...

man页仍然说使用-l-u user结合使用应该可以工作,所以这似乎仍然是一个错误。-U的作用似乎是测试如果由不同的用户调用时可以做什么,而-u是用于以非root用户身份运行命令。查询“如果我,当前调用用户,以非root UID身份sudo,可以执行哪些命令”是一种不同的情况,似乎不被支持。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接