Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 a Raspberry Pi running ArchARM, and would like to make a reverse SSH tunnel as soon as it connects to the network via ethernet.

I made an executable (+x) shell script in /usr/bin, and would like that to be run whenever the default network manager acquires an IP on the eth0 interface.

Alternatively, what is the best way I could do this without an SSH tunnel or opening a port on my router?

share|improve this question
up vote 2 down vote accepted

you can make a reverse SSH with the -R arg (i wrote an article in french about this here ) and cron or make a service with.

here the stuff translated

user@mynewRaspberry :~$ ssh -R 61337:localhost:22 

after you can login it from another place, here in example from

z8po@hive :~$ ssh -p 61337

Next let's use a while loop in your script to check the ssh is forever relaunch.

while true do ssh -R 61337:localhost:22 done

you can maintain your connection with a keep alive on a ssh client or a server, add to /etc/ssh/sshd_config or ~/.ssh/config the folowing line

 ClientAliveInterval 60

Don't forget to use rsa key insteed of paswsrod for auto login without prompt, or if you really want to use password, change the ssh command with user:password@ip but it is quite less secure.

First method Cron it

make a script checking if allready launched, in /home/USER/

if ps -ef | grep -v grep | grep ; then
        exit 0
        while true do ssh -R 61337:localhost:22 done
        exit 0

and edit you crontab

crontab -e

add it after the other crons jobs; every 5 min launch the previous script (which will not work if already running)

   */5 * * * * /home/USER/

Second method : service at startup

create or copy the script in init.d add the commands in to it using vi:

  sudo nano /etc/init.d/

make it executable

  sudo chmod +x /etc/init.d/

update-rc.d to create and configure start:

  sudo update-rc.d defaults

now you have two methods to make your rasperry trying to connect

share|improve this answer
Ooh, I feel dumb. Thank you! – tekknolagi Jun 1 '13 at 17:50
Though I don't understand... why is there a while loop in the cron script? – tekknolagi Jun 1 '13 at 17:51
because of service at startup, it will launch one time, and if crash, relaunch it etc... – z8po Jun 2 '13 at 14:21

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.