I would like to be able to use locally added ssh key to agent on remote host without calling ssh-add on remote.

john@john-VirtualBox:~$ ssh-add ~/.ssh/ansusersu_rsa
Enter passphrase for /home/john/.ssh/ansusersu_rsa: 
Identity added: /home/john/.ssh/ansusersu_rsa (ansusersu@galaxy)
john@john-VirtualBox:~$ ssh ansusersu@ 'sudo whoami'
john@john-VirtualBox:~$ ssh ansusersu@ 'sudo whoami'
john@john-VirtualBox:~$ ssh ansusersu@ 'ssh ansusersu@ '"'"'sudo whoami'"'"''
Host key verification failed.

What I mean, after I loaded key to agent I'm able to connect to both hosts & When I execute a command on in there I do some access to and now it shows "Host key verification failed", but I would like to make it work. Is it possible to make it work? In reality I need to do on rsync of a folder from

1 Answer 1


Host key verification failed.

says that the authenticity of server was not verified, because it's host key is not in the known_hosts of So first of call, manually connect to the and from there to and verify the host key.

Then you can use ssh-agent forwarding (-A switch):

ssh -A ansusersu@ 'ssh ansusersu@ sudo whoami'
  • Thank you very much. I was about to answer my question. Another option to "-A" is to add into ~/.ssh/config 2 lines: "Host * ForwardAgent yes ". But that option is not good from security point Dec 25, 2016 at 15:54
  • Yes, enabling that for all the hosts is not a good idea.
    – Jakuje
    Dec 25, 2016 at 15:55

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.