I'm writing an init script which is supposed to execute a single command as a user different than root. This is how I'm doing it currently:
sudo -u username command
这通常在Ubuntu/Debian上正常工作,但在RHEL上,作为command
执行的脚本挂起
I'm writing an init script which is supposed to execute a single command as a user different than root. This is how I'm doing it currently:
sudo -u username command
这通常在Ubuntu/Debian上正常工作,但在RHEL上,作为command
执行的脚本挂起
在RHEL系统上,/etc/rc.d/init.d/functions
脚本旨在提供类似于您所需的内容.如果在init脚本的顶部找到它,那么它的所有函数都将可用.
为此提供的具体功能是daemon
.如果您打算用它来启动一个类似守护进程的程序,一个简单的用法是:
daemon --user=username command
如果这对您的需求来说太过苛刻,则有runuser
个(完整信息请参见man runuser
;某些版本可能需要在用户名前加-u
):
/sbin/runuser username -s /bin/bash -c "command(s) to run as user username"