8

How to configure ssh to imitate this:

ssh [email protected] -i /path/to/.ssh/server-1-ssh-key -t ssh [email protected] -i /home/server1-user-name/.ssh/server2-ssh-key

When I execute

ssh server2

Explanation:

  • I'm login to server1.net with a key from my local machine (/path/to/.ssh/server-1-ssh-key)

    ssh [email protected] -i /path/to/.ssh/server-1-ssh-key
    
  • then I log in to a server with the following IP 10.0.0.10. To do this I use the key (/home/server1-user-name/.ssh/server2-ssh-key), which is stored on server-1

How should the ssh configuration look like for this case on my local machine?

I tried the following configuration:

Host server2
  Hostname 10.0.0.10
  User server2-user-name
  ForwardAgent yes
  ProxyCommand ssh -i /path/to/.ssh/server-1-ssh-key -W %h:%p

But it does not work.

2 Answers 2

6

So basically you want server1 to act as your jumpbox, so you need one stanza for server1:

Host server1
Hostname server1.net
User server1-user-name
IdentityFile /path/to/.ssh/server-1-ssh-key

Then you need a stanza for server 2 that jumps through this one:

Host server2
Hostname 10.0.0.10
User server2-user-name
ForwardAgent yes
ProxyCommand ssh server1 nc %h %p 2> /dev/null
IdentityFile /home/server1-user-name/.ssh/server2-ssh-key
1

You need to set AllowAgentForwarding on your both your servers' sshd_config files. You may also need to set ForwardAgent in the client config on server 1.

See: https://help.github.com/articles/using-ssh-agent-forwarding

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .