Skip to content

Instantly share code, notes, and snippets.

@tristanmorgan
Last active October 28, 2022 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tristanmorgan/b3a25bc346a73cdfe4d76521c637fa2c to your computer and use it in GitHub Desktop.
Save tristanmorgan/b3a25bc346a73cdfe4d76521c637fa2c to your computer and use it in GitHub Desktop.
ssh/config with proxy environment switch.
Host *
StrictHostKeyChecking no
ServerAliveInterval 60
FingerprintHash md5
VisualHostKey yes
ControlPath /tmp/%r@%h:%p
IdentityFile ~/.ssh/id_rsa
Host github.com
ControlMaster auto
ControlPersist yes
Match Host github.com exec "env | fgrep -q HTTPS_PROXY"
User git
HostName ssh.github.com
Port 443
ProxyCommand /usr/bin/nc -x 127.0.0.1:3128 -X connect %h %p
Host bastion 35.201.4.241
HostName 35.201.4.241
Port 22
Host 10.0.0.*
ProxyJump bastion
@tristanmorgan
Copy link
Author

The magic I'm trying to achieve is to use a tunnel through a proxy only if the proxy env var is set. Assuming the proxy refuses to connect to non-http ports, github provides ssh on port 443 if you connect to the alternative host ssh.github.com

@tristanmorgan
Copy link
Author

P.S. "nc" does the job that we used to use corkscrew for....

@tristanmorgan
Copy link
Author

P.P.S. has ProxyJump been around for long? skips the classic ProxyCommand ssh -W %h:%p -q bastion

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