如何在脚本中以不同用户身份执行 sudo?
我有一个包装脚本,它调用两个脚本 aaa.sh 和 bbb.sh。这两个脚本应该以不同的用户身份执行,例如
sudo -H -u user1
。 /user/bin/scripts/aaa.sh
sudo -H -u user1
。 /user/bin/scripts/bbb.sh
但 sudo 命令无法在脚本内执行。需要帮助...
I have a wrapper script which calls two scripts aaa.sh and bbb.sh. These two scripts should be executed as different users as
sudo -H -u user1
. /user/bin/scripts/aaa.sh
sudo -H -u user1
. /user/bin/scripts/bbb.sh
but the sudo command can't be executed inside a script. Need help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你只是想切换用户,你应该使用“su”而不是 sudo,对吗?
(除非您确实需要提升权限)
If you just want to switch users, you should use 'su' not sudo, right?
(that is unless you actually do need elevated privileges)
sudo
可以在脚本内部使用,但是执行此脚本的用户实际上是否允许使用sudo
?检查您的/etc/sudoers
文件。sudo
can be used inside a script, but is the user that executes this script actually allowed to usesudo
? Check your/etc/sudoers
file.仅当用户名映射到 /etc/sudoers 文件中(如上所述)时才可以使用 sudo。但与 su 用户相比,他可能没有完整的权限。
sudo can be used only if the user name is mapped in /etc/sudoers file as mentioned above. But he may not have the complete priveleges as compared to su user.