Setting up a default gateway in ssh_config

I'd like to know whether there is a way to assign a default ssh gateway to a hostname such that, whenever you attempt to ssh to the hostname it uses the gateway to reach the host. Ideally this should be done in the ssh_config

e.g.: client C attempts to reach target T by

ssh T

The only way this connection can be established is through gateway GW

ssh -tA GW ssh T

EDIT: I neglected to mention that one may have various gateways which will reach different hosts

EDIT: I tried using the ssh config:

Host my-target-host
ProxyCommand ssh -tA GW ssh %h

But then I get "Pseudo-terminal will not be allocated because stdin is not a terminal"

EDIT: Okay so I figured it out :-) The correct config looks like this:

Host my-target-host
ProxyCommand ssh my-gateway-host exec nc %h %p

Not entirely sure why this works though...

3

1 Answer

After some tinkering and searching, I found that this works (for reasons that are beyond me):

In your ssh_config:

Host my-target-host
ProxyCommand ssh my-gateway-host exec nc %h %p
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like