繁体   English   中英

在执行bash脚本期间如何更改用户身份,并继续以新用户身份运行命令?

[英]How can I change users in during my bash script excecution and continue running commands with the new user?

因此,我正在为安装制作一个ubuntu bash脚本,在其中,我必须将用户更改为postgres用户(运行sudo su postgres ),然后我必须输入postgres shell并运行一些命令。 问题是,当我将用户更改为postgres用户时,命令将继续以root用户运行。 如何使用postgres用户运行这些命令?

当您运行sudo su user您将切换到该用户shell,但是您的脚本仍在您的第一个root shell中,并且正在等待sudo su user完成,以便可以继续。

您应该像这样为另一个用户运行每个命令: sudo -u other_user your_command

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM