Skip to content

Instantly share code, notes, and snippets.

@jmnsf
Created April 21, 2017 04:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jmnsf/1844e139df401cd8aa9e5e600badcc4e to your computer and use it in GitHub Desktop.
Save jmnsf/1844e139df401cd8aa9e5e600badcc4e to your computer and use it in GitHub Desktop.
SSH Tunnel Setup

SSH Tunnel Setup

Use this for protected networks where port 22 isn't available, or for general security reasons where your traffic will be routed through an external server via SSH tunnel.

Server Setup

An EC2 micro instance or a tiny DigitalOcean droplet will work for this. For the initial configuration, access to port 22 is required, as you'll have to SSH onto your host.

In the host, edit /etc/ssh/sshd_config and add the line Port 443. Reboot. From now on you can SSH into the server through port 443 (ssh -p 443 user@server).

Tunnel Setup

Just run, in any terminal, ssh -vND 1080 -p 443 user@server. This will start a SOCKS server on port 1080 of your machine.

You can now configure your system to use a SOCKS proxy on localhost:1080.

Git

Git's doesn't use the system SOCKS settings, so we have to get fancy. Edit ~/.ssh/config and add the following:

Host git.corp.example.com
  ProxyCommand=nc -X 5 -x localhost:1080 %h %p

Where git.corp.example.com is the server where your repo is located (eg: github.com). This uses the netcat tool.

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