![]() |
Starting processes as a specific user?
I've got a script which needs to be run on system startup, as a specific user. As I understand, to start something automatically I can add it to /etc/rc.d/rc.local, but this will start up as root, correct?
Thanks in advance M |
it will by default, but you can do something like "su -l myotherusername -c command" and it should run. of course, if it's a program which does not fork nicely (i.e. a daemon) then it'll hang the boot at that stage while it's running.
|
You could just as well create a script which you run from ("call from") rc.local; the script would be like
Code:
#!/bin/bash |
no, that won't work, the su command spawns a login shell, and just sits there. it won't process the other commands as the new user. only when that su terminates is the rest of the script executed:
Code:
[root@server scripts]# su ac-phillipc; whoami |
Another solution would be to write the commands (to be executed as the non-root user) in a script
and then to: Code:
chown your_user:some_group the_script |
hmm yes, that's an idea. depends how many comamnds you need, wouldn't be worth it for a single lline, but anythign lareger and it could easily be useful.
|
For the one-liner, the -c option to su can easily be used, no?
|
| All times are GMT -5. The time now is 07:10 AM. |