Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am scripting a remote rsync setup, and need to add a remote server to the local known_hosts file to avoid getting prompted wit the below when the script is first ran:

The authenticity of host '[hostname] ([IP address])' can't be established. RSA key fingerprint is [key fingerprint]. Are you sure you want to continue connecting (yes/no)?

As per Can I automatically add a new host to known_hosts? I have tried (with a fresh known_hosts file):

ssh-keyscan -H [hostname],[ip_address] >> ~/.ssh/known_hosts
ssh-keyscan -H [ip_address] >> ~/.ssh/known_hosts
ssh-keyscan -H [hostname] >> ~/.ssh/known_hosts

But this does not work, I am always prompted to accept the finger-print.

When I do let ssh add this for me, the key hash is very different in the know_hosts file.

What else should I do to troubleshoot this issue?

share|improve this question
up vote 4 down vote accepted

Try this:

ssh-keyscan -t rsa [ip_address]

Take the output and paste it in .ssh/known_hosts. Now if you want to hash known_hosts do this:

ssh-keygen -H

edit: Heres the one command solution. It uses hostname and IP addresses and hashes both.

ssh-keyscan -Ht rsa [hostname],[IP address] >> known_hosts
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.