I read several versions of this question and try to implement them but they did not work so I want to ask my problem with specific details.

Host A: Local Computer

Host B: Intermediate computer ( I can access from my local with using a public key, foo.key

Host C: Final Computer ( I can access it from Host B)

I followed commands like:

ssh -J user@hostA.com user@hostB.com 

But where to put key?

When I try something like:

 ssh -i foo.key -J user@hostA.com user@hostB.com

It gives error too.

  • The actual name for what you're trying to do is an SSH Multi-Hop... see this answer – JW0914 Sep 12 at 11:59
  • Thanks I read this page too before asking, but any of the examples includes a key file. How can I declare the key file while multi-hopping? – usoysal Sep 12 at 12:02

The general syntax is ssh -J <intermediates> <final>, so according to the information you provided, the actual command should be:

ssh -J user@hostB user@hostC

If using -J or ProxyJump, all connections are made by a locally running client, so all private keys must be available on the local system only.

The -i option only allows specifying the same keys for all connections. If different hosts (e.g. intermediate vs final) need different keys, you'll need to specify them in ~/.ssh/config (or load them into ssh-agent):

Host hostB
    IdentityFile ~/bastion.key

Host hostC
    IdentityFile ~/finalserver.key

(You can specify User user and/or ProxyJump user@hostB in the same file, if you want.)

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.