You are not logged in.

#1 2009-02-03 06:18:34

Heresyte
Member
Registered: 2008-07-10
Posts: 19

rc.local, run command as regular user?

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

#2 2009-02-03 07:20:48

darthaxul
Member
Registered: 2008-09-24
Posts: 156

Re: rc.local, run command as regular user?

have u tried the su command?

Offline

#3 2009-02-03 08:31:11

Envil
Member
Registered: 2008-11-18
Posts: 52

Re: rc.local, run command as regular user?

su with -c should do the trick

example: su nyx -c vncserver

Offline

#4 2009-02-03 12:41:00

Surgat_
Member
Registered: 2007-08-08
Posts: 317

Re: rc.local, run command as regular user?

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

#5 2009-02-03 17:03:40

Heresyte
Member
Registered: 2008-07-10
Posts: 19

Re: rc.local, run command as regular user?

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

#6 2009-02-03 17:35:31

Envil
Member
Registered: 2008-11-18
Posts: 52

Re: rc.local, run command as regular user?

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

Board footer

Powered by FluxBB