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. 

TIP: 

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?

Connect:

$ sftp -P 12345 anuser@localhost

List files/folders:

sftp> ls

Download:

sftp> get test.zip

Upload:

sftp> put test2.zip

Download a file with resume support:

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

Upload a file with resume support:

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

More: How to Resume Download/Upload over SSH

References:

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

Comments

14 + 3 =
Home | Search | Contact | Terms
Editor