[英]sudo su to an other user to run script
I am trying to login as USER1 and switch user to USER2 and execute some scripts (100+ scripts, can't list them all out in the sudoer file one by one) as USER2 我正在尝试以USER1身份登录并将用户切换到USER2并以USER2身份执行一些脚本(超过100个脚本,无法将它们全部逐个列出在sudoer文件中)
in the Sudoer file i have 在我的Sudoer文件中
USER1 ALL=(USER2) NOPASSWD: ALL
When i run the following as USER1 当我以USER1身份运行以下命令时
sudo su - USER2 -c "test.sh"
I get 我懂了
Sorry, user USER1 is not allowed to execute '/bin/su - USER2 -c test.sh' as root 抱歉,不允许用户USER1以root身份执行'/ bin / su-USER2 -c test.sh'
if i run 如果我跑
sudo su - sassrv
I get 我懂了
Sorry, user USER1 is not allowed to execute '/bin/su - USER2' 抱歉,不允许用户USER1执行'/ bin / su-USER2'
If i change the Sudoer file to 如果我将Sudoer文件更改为
USER1 ALL=(ALL) NOPASSWD: /bin/su - USER2
It will let me switch user, but i am still getting 它可以让我切换用户,但是我仍然可以
Sorry, user USER1 is not allowed to execute '/bin/su - USER2 -c test.sh' as root 抱歉,不允许用户USER1以root身份执行'/ bin / su-USER2 -c test.sh'
How can i achieve this? 我怎样才能做到这一点?
You wanted to run test.sh
as USER2 with sudo
, but instead you run su
as root. 您想使用sudo
以USER2身份运行test.sh
,而是以root身份运行su
。
su
may in turn try to run test.sh
as USER2, but that's beyond the scope and knowledge of sudo
. su
可能会尝试以USER2身份运行test.sh
,但这超出了sudo
的范围和知识。 From sudo
's point of view, the only thing you're doing is trying to run a command as root. 从sudo
的角度来看,您唯一要做的就是尝试以root用户身份运行命令。
Instead, ask sudo
to run test.sh
as USER2 directly: 相反,要求sudo
以USER2身份直接运行test.sh
:
sudo -u USER2 test.sh
PS: sudo su
in any context is a code smell that indicates a lack of understanding of what sudo
is and does. PS: sudo su
在任何情况下都是一种代码味道,表明对sudo
是什么和做什么缺乏理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.