3 ms·
This overlooks ProxyCommand, the single most useful reason for using an ssh config file. e.g.: Host internal-*.example.net ProxyCommand ssh -T ext
by sneak 14y ago
This overlooks ProxyCommand, the single most useful reason for using an ssh config file.
e.g.:
Host internal-*.example.net
ProxyCommand ssh -T external.example.net 'nc %h %p'
Basically, specify as ProxyCommand whatever command needs to be run to give you i/o to the remote sshd - in this case, sshing to a bastion host and running netcat. This allows me to do, for example:
ssh internal-dev.example.net
Which will (in background) ssh to the bastion host external.example.net. I can even do port forwards to internal hosts using -L or LocalForward directives. It's a huuuuge timesaver.
ssh even automatically replaces %h and %p in the ProxyCommand with a host and port, though you can of course replace those tokens with static values if it works better.
(Also, note above that one can use wildcards in Host declarations.)
- ceejayoz 14y agoThat is freaking awesome.
- jperras 14y agoAh, very cool. I remember stumbling upon ProxyCommand in some SSH docs, but didn't really see an immediate use for it. Thanks!
- mrud 14y agoYou can also use ssh -W [1] instead of relying on nc, i.e: Host madeup Host internal_name ProxyCommand ssh external.example.net -W %h:22 [1] - http://manpages.debian.net/cgi-bin/man.cgi?query=ssh&apropos=0&sektion=0&manpath=Debian+6.0+squeeze&format=html&locale=en http://manpages.debian.net/cgi-bin/man.cgi?query=ssh&apr...
- stock_toaster 14y agoNote there appears to be a bug where the use of ControlPersist breaks the use of '-W'. You end up with 'bad packet'. openssh-6.0 release notes has this: * sshd(8): unbreak stdio forwarding when ControlPersist is in use; bz#1943 I haven't tested to see if that resolves the issue yet though (on osx which of course does not have 6.0). However, the netcat version works fine.
- ryan-c 14y agoA generalized version of that: https://github.com/ryancdotorg/ssh-chain https://github.com/ryancdotorg/ssh-chain It will let you do ssh internal-dev.example.net^external.example.net
- HerraBRE 14y agoI use the same technique to access VPS machines and mobile devices, except instead of a fixed bastion host I relay the connections through PageKite (disclosure: I'm the author). It feels a bit magical to just be able to ssh into a laptop or Android phone, no matter which network it is on. :-) The PK/SSH HowTo: https://pagekite.net/wiki/Howto/SshOverPageKite/ https://pagekite.net/wiki/Howto/SshOverPageKite/
- olalonde 14y agoWhy not directly ssh into "external.example.net"? Why is this a time saver? I'm not sure what you use this for...
- luser001 14y ago1. Two commands instead of one. :) 2. Scripting an scp, rsync etc from the internal machine is easier now, since the ssh from the external to internal machine is handled transparently for you.
- rubyrescue 14y agoi've seen this used for security, in that you can have an extra external server you must have access to in order to get to internal servers.
- olalonde 14y agoAh ok, this make sense especially if some of your machines are on the same LAN but don't have an external IP.