Skip to content

Instantly share code, notes, and snippets.

@ojacques
Last active July 22, 2021 11:39
Show Gist options
  • Save ojacques/c738fcb001f674d95c0a46a877b41baa to your computer and use it in GitHub Desktop.
Save ojacques/c738fcb001f674d95c0a46a877b41baa to your computer and use it in GitHub Desktop.
GitHub ssh/git behind proxy or on restrictive VPN

Issue: can't use ssh or git commands when connected on VPN. This is because, for now, outgoing ssh / TCP 22 is blocked.

We have to tunnel through the web proxy. Here is how:

On Windows

  • Download and install nmap-7.70-setup.exe from https://nmap.org/download.html. We will use ncat tool to send all packets through the proxy.
  • Open command line (WIN Key+R+cmd+ENTER)
  • cd %USERPROFILE%\.ssh. This is where you have stored your ssh private key for GitHub
  • Create a new file named config
  • Add
Host github.com
  Hostname github.com
  port 22
  ProxyCommand ncat --proxy <your-http-proxy>:8080 %h %p
  identityfile ~/.ssh/github.privatekey.pem

On Linux

  • We will use ncto send all packets through the proxy.
  • Edit ~/.ssh/config: nano ~/.ssh/config |
  • Add
Host github.com
  Hostname  github.com
  port 22
  ProxyCommand nc -X connect -x your-http-proxy:8080 %h %p
  identityfile ~/.ssh/github.privatekey.pem
  • If you use ArchLinux, you can use socat: ProxyCommand socat - PROXY:web-proxy:%h:%p,proxyport=8080
  • Issue chmod 400 ~/.ssh/config to set permissions right for this file

📝 Replace "web-proxy" with the proper web proxy which works at your site, and github.privatekey.pem with your actual private key file.

Usage

You can then use git commands as usual, with git URLs:

git clone git@github.com:your_user/your_repo.git

⚠️ when your PC is directly connected to the internet and you want to use github.com, you will have to comment out the ProxyCommand line in your ssh/config.

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