Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

up vote 2 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

 
discard

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.