[英]How can I execute a series of commands in a bash subshell as another user using sudo?
[英]How can I execute commands as another user with their .bash_profile instead of the current user's?
我想在啟動腳本(rc.local)中以非root用戶身份運行命令。 我要執行的命令實際上是非root用戶的.bash_profile中的別名。 我嘗試使用
su - myuser -c aliased_cmd
但這不起作用。 如果我只是鍵入
su - myuser
# wait for login...
aliased_cmd
它工作正常,但顯然這在實際腳本中是不合適的。 當然,我可以將要使用的別名和函數復制到實際的rc.local文件中,但這似乎有點愚蠢……也許有我不知道的選項或使用sudo的方法這個?
在獲取配置文件后,包括以下內容
shopt -s expand_aliases
man su
:
使用-時,必須將其指定為最后一個su選項。
如果不是最后一個選項,它沒有指定會發生什么。 另外,在提要中,用戶名在所有選項之后。
您是否嘗試過su -c aliased_cmd - myuser
或su -l -c aliased_cmd myuser
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.