SSH to server on a closed network

I recently decided that I would like backup all my /home files on my Debian server to a remote server. Luckily one of my friends also had a Debian server, where I could backup my files to. However this server resided on a closed network behind a firewall, so I was not able to SSH into the machine.

I order to solve this problem, I setup the backup to SSH to my server, opening a local port on my server, which I could use to SSH through. I the following section, I will explain the steps, in order to recreate this setup.

On the remote server (the Backup server) I created a script, called sshloop.sh with the content:

#!/bin/bash
while [ 1 ]
do
echo "Starting ssh..."
ssh -nNT -R 6655:localhost:22 backupuser@mydomain.dk
echo "SSH ended..."
sleep 60
done

This script will continuously create a SSH session to my server, with a local port 6655. This requires, that a passwordless private/public key resides between the two machines. [I will soon create a guide for this].

Now I am able to SSH through the existing SSH tunnel to the remote server using the following command

ssh –p 6655 localhost

Now you should be prompted for the remote server password. Now you have a SSH shell on a server that resides on a closed network.

For details on my backup solution, you can read about it here

Leave a Reply