I have several Hosts in ~/.ssh/config, and they work fine from local machine, but remote machine doesn't know these Hosts.

Host A
    HostName github.com
    IdentityFile ~/.ssh/A_rsa
Host B
    HostName github.com
    IdentityFile ~/.ssh/B_rsa
Host remotemachine.com
    ForwardAgent yes

From localhost:

$ ssh -T git@A
Hi A! You've successfully authenticated, ...
$ ssh -T git@B
Hi B! You've successfully authenticated, ...

From remote host:

$ ssh remotemachine
$ ssh-add -l
  ... both keys present ...
$ ssh -T git@B
ssh: Could not resolve hostname B: Name or service not known
$ ssh -T [email protected]
Hi A! You've successfully authenticated, ...

How to use key B on remote machine?

That said, from local machine I'm able to do ssh git@B, but on remote machine hostname B is not known. Seems like ssh-agent forwards only keys, but not hosts. How to make it forward hosts too?

I could create ~/.ssh/config on remote machine too, but what to put into IdentityFile? I could use $ ssh -i KEYFILE, but what to put into KEYFILE if keys are forwarded?

1 Answer 1


Yes, the only way to do this is to use ssh -i or to create ~/.ssh/config on every machine, with the same IdentityFile settings.

However, it is enough to copy the public keys to other servers. That is, not ~/.ssh/A_rsa, but only ~/.ssh/A_rsa.pub. The ssh client will use the agent for private keys, just like it already does on your local machine.

You must log in to answer this question.

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