Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to setup port forwarding on system start and have this configured in my rc.local

runuser -l phpAdmin -c 'ssh -f -N -L 9904:localhost:3306 phpAdmin@<server>'

When rc.local is executed, is it executed as root?

share|improve this question
You really have an user phpAdmin in /etc/passwd, with a valid shell entry? – ott-- Dec 7 '12 at 9:35
If this a rhetorical/sarcastic question, I am missing it. Could you please elaborate? Is this a bad security practice? – foobarmoo Dec 7 '12 at 10:06
I'm searching for an explanation why it's not running as user phpAdmin. – ott-- Dec 7 '12 at 10:32
It is working fine, I just want to make sure that this is the right way to do this. – foobarmoo Dec 7 '12 at 10:47
up vote 0 down vote accepted

rc.local is executed as root user, but this is not probably the place to start such tunnel because if you get any problem (even a temporary network problem), your tunnel will be stopped forever. A better solution is to put it in /etc/inittab file, so that your init process may run it in your correct runlevel, and respawn it if it crashes. If you run it from inittab remove the "-f" flag from ssh invokation, otherwise init will not be able to detect ssh failing.

share|improve this answer
Do you mean add an entry in inittab itself or create an entry like /etc/init.d/foo with foo having the port forwarding script? – foobarmoo Dec 7 '12 at 10:14
in inittab, like "TT:23:respawn:/bin/su phpAdmin -c 'ssh ...'" – eppesuig Dec 7 '12 at 10:57
Now that we are on it, a question, what is the difference between doing it in init tab versus adding another entry under init.d? If you can point me to a link also, I would be very happy. Thanks for the help. – foobarmoo Dec 7 '12 at 12:10
in inittab you just put a command line and it will be executed when init switch run level. In init.d you store scripts and you may invoke them with an argument (usually start/stop/restart/status) and you may have many scripts in the same runlevel (just link them from /etc/rcN.d where N is the runlevel) and you may sort them. More info to /etc/init.d startup sequence depends on what startup procedure you are using: check all "upstart" "systemd" "sysv-rc" – eppesuig Dec 7 '12 at 13:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.