如何在脚本中以不同用户身份执行 sudo?

发布于 2024-10-06 18:49:59 字数 217 浏览 0 评论 0原文

我有一个包装脚本,它调用两个脚本 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

飘然心甜 2024-10-13 18:49:59

如果你只是想切换用户,你应该使用“su”而不是 sudo,对吗?

su user1 -c ./user/bin/scripts/aaa.sh

(除非您确实需要提升权限)

If you just want to switch users, you should use 'su' not sudo, right?

su user1 -c ./user/bin/scripts/aaa.sh

(that is unless you actually do need elevated privileges)

妄断弥空 2024-10-13 18:49:59

sudo 可以在脚本内部使用,但是执行此脚本的用户实际上是否允许使用 sudo ?检查您的 /etc/sudoers 文件。

sudo can be used inside a script, but is the user that executes this script actually allowed to use sudo? Check your /etc/sudoers file.

得不到的就毁灭 2024-10-13 18:49:59

仅当用户名映射到 /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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文