在 sudo bash 脚本中更改用户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6537127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:16:25  来源:igfitidea点击:

change user in sudo bash script

bashshellubuntusudo

提问by ivoba

In a bash script that is called with sudo i am calling:

在使用 sudo 调用的 bash 脚本中,我正在调用:

/usr/bin/firefox -new-tab http://stackoverflow.com

/usr/bin/firefox -new-tab http://stackoverflow.com

but then i get the message:

但后来我收到了消息:

Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system

Firefox 已在运行,但没有响应。要打开新窗口,您必须先关闭现有的 Firefox 进程,或者重新启动系统

this is, i guess, because the script is called by sudo and firefox by the normal user. if i would call the command without sudo it works.

我猜这是因为脚本是由普通用户通过 sudo 和 firefox 调用的。如果我在没有 sudo 的情况下调用命令,它会起作用。

so how can i switch back to the normal user in a sudo called script?

那么如何在名为 script 的 sudo 中切换回普通用户?

回答by Francisco R

using sudo again inside your script.

在脚本中再次使用 sudo 。

sudo -u user -H /usr/bin/firefox -new-tab http://stackoverflow.com

回答by CharlesB

This postmight answer your question

这篇文章可能会回答你的问题