You are not logged in.
Pages: 1
I want to run a command at startup that can't safely be run as root (and I don't want it to be anyway). The only way I know of to execute a command at startup is rc.local, but that will run the command as root. I know sudo can be used to run commands as other users. If I use sudo to change what user the startup command is running as, will that be safe? In other words, will that effectively make it as if it was being run by a regular user instead of root? Or is there a better way of doing this? Thanks.
Offline
have u tried the su command?
Offline
su with -c should do the trick
example: su nyx -c vncserver
Offline
You can also put it in your .bashrc, so it will be executed every time you log in. For example, I have it set to mount my external disc if it's plugged but not mounted:
if [[ -r /dev/disk/by-label/disco-externo && `mount | grep disco-externo | wc -l` -eq 0 ]]
then
sudo mount /dev/disk/by-label/disco-externo /mnt/disco-externo
fi
If you put the sudo away you can start any command as a regular user under certain circumstances.
Offline
What's the difference between sudo and 'su -c'? Is there a reason to prefer 'su -c' in a situation like this?
Using .bashrc won't work because I don't want it to be run when I login. Sometimes I turn on my computer without logging in right away and I want the command to be run as soon as the computer boots up. So since the boot scripts run commands as root I really need a safe way for root to run a command as a regular user.
Offline
There shouldnt be any security issues or atleast i cant think of any ^^
su -c seems to be simpler than using sudo but no idea if theres any differences besides that.. most likely not.
Offline
Pages: 1