簡體   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