LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   run a script in boot as user using /etc/rc.local (https://www.linuxquestions.org/questions/linux-general-1/run-a-script-in-boot-as-user-using-etc-rc-local-4175560332/)

hnasr2001 12-01-2015 02:52 PM

run a script in boot as user using /etc/rc.local
 
I am trying to run a script at boot using /etc/rc.local.
it works fine but runs as root and I want to run it as user.
I tried sudo -u user /path-to-file and it didn't work (the script didn't run).
Any solution will be appreciated.

Emerson 12-01-2015 02:58 PM

See man setuid and man setuidgid.

suicidaleggroll 12-01-2015 03:42 PM

How about "su - user -c command"?

Emerson 12-01-2015 04:02 PM

su will work, too.

Below is a live example with setuidgid.
Code:

#!/bin/sh
exec setuidgid sarah /usr/local/bin/mplayer -quiet http://...


hnasr2001 12-05-2015 08:32 PM

Thanks everyone - su worked.


All times are GMT -5. The time now is 11:29 AM.