Reverse SSH (Accessing without port forwarding)

I needed to access a computer that behind firewall and uncontrolled router. So, I can't do port forwarding. 
The computer on behind firewall is Ubuntu and I want to access it from CentOS that I can control it.

After searching a lot, I realized there is "reverse SSH" technique that accomplish this. 

Here is the steps I followed.

Step 1: I installed openssh server on the computer (Ubuntu) that I want to access later.

sudo apt-get install openssh-server

Step 2: From Ubuntu I connect to Centos with following:

ssh -R 12345:localhost:22 anuser@CentOSIP

We can use another unused port instead of 12345

Step 3: If the login on step 2 is successful, then I can access Ubuntu from CentOS by following:

ssh localhost -p 12345

or login with specified Ubuntu user

ssh anuser@localhost -p 12345

That's it! Now you can access the computer (Ubuntu) without port forwarding. 


We also can use CentOS (for this example) like proxy server and we can access Ubuntu from another computer. 

Firstly we need to login to CenOS server

ssh anuser@CentOSIP

After logged in CentOS that we can access Ubuntu which is behind router by following command:

ssh anuser@localhost -p 12345

How to transfer file on reverse SSH?


$ sftp -P 12345 anuser@localhost

List files/folders:

sftp> ls


sftp> get


sftp> put

Download a file with resume support:

$ rsync --partial --progress --rsh='ssh -p 12345' anuser@localhost:/remote/path/  /local/path

Upload a file with resume support:

$ rsync --partial --progress --rsh='ssh -p 12345' anuser@localhost:/remote/path

More: How to Resume Download/Upload over SSH


Share Share Editor: editor | Posted: 2013/03/28 | Views: 6010


16 + 18 =
Home | Search | Contact | Terms