This link goes to an article on transparent multihop ssh. It gives a solution that works for me in a similar situation. I just tested this going from MacOS X through a linux box to another linux box and it worked. Your mileage may vary with other environments.
Using the names you gave above, put this in $HOME/.ssh/config
.
Host GW2
ProxyCommand ssh -q GW1 nc GW2 22
Host server1
ProxyCommand ssh -q GW2 nc server1 22
I've used scp
over this type of setup and it works fine. The referenced article gives more details, but the proxy command directive gives it a pre-configured way to access that host that's transparent to the end user.
One thing to note, the article specifies using nc -q0
, but that option isn't available on the stock nc
on my ubuntu VM or my mac. It seems to work fine without it and a few minutes of searching left me no closer to figuring out what -q0
is supposed to do.
If anyone knows and wants to include it here, I'll happily update my answer.