I want to SSH to a machine C from machine A through B. Usually I would do:

A$ ssh user@B
B$ ssh user@C

I have to type passwords both times (no public key allowed). I would like to set up a control socket so that after typing both passwords I can ssh to C using the socket, perhaps typing something like:

A$ ssh -S socket C

Is this possible?


You can use B as a jump host:

ssh -J user@B user@C

If your usernames or hostnames are long, you can add them to ~/.ssh/config:

Host hostB
    HostName some-long-hostname-of-B-or-its-ip
    User username-on-B

Host hostC
    HostName same-here-for-C
    User username-on-C

Then you can ssh like this:

ssh -J hostB hostC

The jump can also be configured for ssh hostC:

Host hostC
    HostName same-here-for-C
    User username-on-C
    ProxyJump hostB
  • @Fernando, I feel like your edits could be posted in an answer of their own - it's your original research based on what I've posted. If you could post them as a new answer, I'll be happy to upvote it. – gronostaj Oct 17 at 13:58

To complement gronostaj's answer, here is how you create a socket with -J:

$ ssh -M -S socket -J user@B user@C -fN

Then to use the socket to log in to C:

$ ssh -S socket C

This way you are not required to type any passwords.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.