Use specific key to connect to jump host without modifying ssh config file

I'm trying to write a script that connect to a linux server by using an other one as a ProxyJump:

ssh -J root@proxyhost root@target 

I have two different keys (actually ssh certificate) and I would like to tell ssh to use one for the proxy host and the other for the target. I know I could modify the ssh config for that but I would like to specify it on the command line so I don't have to rely on a valid ssh configuration.

So I'm looking for something like:

ssh -i proxyhostkey -J root@proxyhost -i targetkey root@target

The ssh man page of the -J options says (emphasis mine):

Note that configuration directives supplied on the command-linegenerally apply to the destination host and not any specified jump hosts. Use ~/.ssh/config to specify configuration for jump hosts.

Is it possible to do want I want ? Or do I have to ensure that the ~/.ssh/config file will be correct ?

1 Answer

No, you'll have to either

  • use two -i parameters and allow ssh to offer both keys to both servers (the order of -i versus -J doesn't matter);

  • or replace -J with a manual ProxyCommand:

    ssh target -oProxyCommand="ssh proxyhost -i ~/otherkey -W %h:%p" -i ~/thiskey

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