Skip to main content

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

Comments

Popular posts from this blog

Install Gradle on Windows

First, please make sure you have PowerShell installed on your Windows machine. And run the following commands: Set-ExecutionPolicy RemoteSigned -scope CurrentUser iex (new-object net.webclient).downloadstring('https://get.scoop.sh') scoop install gradle And then you can run   gradle --version if you see something like: Build time:   2017-04-10 13:37:25 UTC Revision:     b762622a185d59ce0cfc9cbc6ab5dd22469e18a6 Groovy:       2.4.10 Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015 JVM:          1.8.0_131 (Oracle Corporation 25.131-b11) OS:           Windows 10 10.0 amd64 This means the Gradle has been installed on your computer successfully.