I wrote the following command in /etc/rc.local:

ssh -R 32400: root@marcin.com -N

but it won't start.

Any idea why?

  • 1
    You can't get an output of commands run in /etc/rc.local as they don't run in a terminal. I guess you want to run this in a terminal / tty once logged in right? Do you login using a GUI or using a tty? – kos Sep 10 '15 at 17:05
  • this runs on Raspberry Pi and i want to run it as fast as RPi boots up – Marcin Marczyk Sep 10 '15 at 17:07
  • Some clarifications: 1) Does it work if run from command line? 2) Does it ask for a password? – Eric Carvalho Sep 10 '15 at 18:30
  • it works from command line, i have added rsa key to server as user and as root – Marcin Marczyk Sep 10 '15 at 19:34

Maybe the network isn't ready yet, when rc.local is executed.

The following code will wait for the network before connecting:

until ping -nq -c3 W.X.Y.Z; do
   # Waiting for network
   sleep 5
ssh -R 32400: root@marcin.com -N

W.X.Y.Z is an IP address that is reachable and replies to pings. It maybe be the default gateway of your network, the Google DNS (, etc.

Code between parenthesis runs in a new shell, and the & makes it run in background. It won't block the execution of rc.local.

The commands between until and done will be repeated until the ping is successful, i.e., it gets a reply (i.e., the network is up).

  • For info rc.local was placed in /etc for me. I also had to ensure it was executable (sudo chmod 775 /etc/rc.local) and place #!/bin/sh -e at the top: askubuntu.com/questions/9853/… – SharpC Feb 8 '20 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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