Skip to content

Instantly share code, notes, and snippets.

@felixrabe
Created September 27, 2014 09:50
Show Gist options
  • Save felixrabe/c534e0a5980bfb3ce336 to your computer and use it in GitHub Desktop.
Save felixrabe/c534e0a5980bfb3ce336 to your computer and use it in GitHub Desktop.
Reverse SSH tunnel

Connect two machines on distinct networks via SSH

localhost below is meant to be used literally.

Topology example

laptop_srv  --  wifi_1
                        >  server
laptop_clt  --  wifi_2
  • laptop_srv: laptop with SSH server to log into

  • laptop_clt: laptop to use with SSH client

  • wifi_1 and wifi_2: access points

  • server: remote server accessible via SSH from both laptop_srv and laptop_clt

Set up tunnel (laptop_srv)

ssh -R 4022:localhost:22 serveruser@server

Also see http://www.howtoforge.com/reverse-ssh-tunneling.

Log in from laptop_clt to laptop_srv

ssh -l serveruser server
# on remote server:
ssh -l laptop_srv_user localhost -p 4022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment