I have two servers, middle
and remote
. middle
is used as a proxy to access remote
. I've set up middle
's ssh config so that it preserves connections to remote
via ControlMaster, as follows
Host remote
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p
ControlPersist yes
I've created a persistent connection from middle
to remote
. This is convenient because the authentication on remote
is complex.
I'd like to set up my local ssh config so that I can ssh from localhost to remote
via middle
, reusing the connection created above. I can do this manually as ssh -t middle ssh remote
, but I can't figure out a way to accomplish the same thing using the ProxyCommand option, which is especially annoying if I want to scp a file to remote
.
ProxyCommands which do not work include
ssh middle -W remote:22
(does not reuse connection)ssh middle -t remote
(goes all the way to a shell, confusing my local ssh client, which is expecting to talk to sshd, not a shell)
Best Answer
I think you misunderstand the whole ControlMaster mechanism in ssh. The idea is that the connection is reused on the LOCAL SYSTEM - that is, on the "middle" server. So, in essence, to reuse the connection, you would need to invoke ssh client on "middle". Like this:
ssh middle "ssh remote"
This will connect you to "middle" first, and then launch an ssh client there, to connect you to "remote". The second connection will, with correct ControlMaster configuration, reuse the existing, persistent, connection.