Skip to content

Instantly share code, notes, and snippets.

@vihuvac
Last active September 30, 2018 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vihuvac/7014542 to your computer and use it in GitHub Desktop.
Save vihuvac/7014542 to your computer and use it in GitHub Desktop.

Reverse SSH Tunneling

I guess you ever wanted to connect to a Linux desktop machine via ssh, but you did not have a way to do it.

The Reverse SSH Tunneling allows you to connect to a computer for it which you do not have access via ssh. The connection is established opening up a tunnel through another computer for it which you really have a ssh access. It works really good with UNIX systems.

Use Case

Requirements

  1. Credentials ( username and password ).
  2. Public IP ( for remote connection via ssh ).

Real Test

The following credentials are using just for this use case, remember the same is just a test for this documentation.

Username Password Remote IP
ubuntu raring1304 138.47.99.99

1. Establish a connection to the remote machine (server):

ssh -R 19999:localhost:22 ubuntu@138.47.99.99

Note

Port 19999 can be any unused port.

2. Now you can SSH from source to your destination through SSH tuneling:

ssh localhost -p 19999

Note

If you cannot connect to your destination machine, you can ask to someone else to open up a tunnel for you, then you could connect straight to your wished destination. In this case you should run ssh destined-username@localhost -p 19999.

The destined-username will be your username on the destined machine you wanted to connect to.

Maybe you should enter your password, the same should belong to your destined-username.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment