Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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 z8po@z8po.dyndns.info 

after you can login it from another place, here in example from z8po.dyndns.info

z8po@hive :~$ ssh z8po.dyndns.info -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 z8po@z8po.dyndns.info 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/autolauncher.sh

#!/bin/sh
if ps -ef | grep -v grep | grep yourscript.sh ; then
        exit 0
else
        while true do ssh -R 61337:localhost:22 z8po@z8po.dyndns.info done
        exit 0
fi

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/autolauncher.sh

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/autolauncher.sh

make it executable

  sudo chmod +x /etc/init.d/autolauncher.sh

update-rc.d to create and configure start:

  sudo update-rc.d autolauncher.sh 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
1  
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

 
discard

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.