Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically accept the remote key when rsyncing?

I'm attempting to make a system which automatically copies files from one server to many servers. As part of that I'm using rsync and installing SSH keys, which works correctly.

My problem is that when it attempts to connect to a new server for the first time it will ask for a confirmation. Is there a way to automatically accept?

Example command/output:

rsync -v -e ssh * root@someip:/data/
The authenticity of host 'someip (someip)' can't be established.
RSA key fingerprint is somerandomrsakey.
Are you sure you want to continue connecting (yes/no)? yes
like image 285
Bravo Delta Avatar asked Aug 08 '13 10:08

Bravo Delta


People also ask

How do I stop SSH from asking for permission?

Also you can give -t keytype were keytype is dsa , rsa , or ecdsa if you have a preference as to which type of key to grab instead of the default. Once you have run ssh-keyscan it will have pre-populated your known-hosts file and you won't have ssh asking you for permission to add a new key.

How do I use rsync with SSH keys?

Using rsync With SSH and Your Key If you want details on what SSH is doing, add "-v" to the ssh options. To run rsync quietly, remove the "-v" option from both rsync and SSH option list. To reverse the synchronization so the remote file is updated on your local computer, reverse the source and destinations.


3 Answers

You can add this host's key to known_hosts beforehand like this:

ssh-keyscan $someip >> ~/.ssh/known_hosts
like image 120
Yorik.sar Avatar answered Nov 09 '22 10:11

Yorik.sar


If they genuinely are new hosts, and you can't add the keys to known_hosts beforehand (see York.Sar's answer), then you can use this option:

-e "ssh -o StrictHostKeyChecking=no"
like image 29
Brian Agnew Avatar answered Nov 09 '22 08:11

Brian Agnew


I know that this was asked 3 years ago, but this was at the top of my google search and I was unable to get either of these solutions in the middle of a Vagrant script to work correctly for me. So I wanted to put here the method that I found somewhere else.

The solution there talks about updating the ~/.ssh/config or /etc/ssh/ssh_config file with the following blocks of code.

To disable host key checking for a particular host (e.g., remote_host.com):

Host remote_host.com
    StrictHostKeyChecking no

To turn off host key checking for all hosts you connect to:

Host *
    StrictHostKeyChecking no

To avoid host key verification, and not use known_hosts file for 192.168.1.* subnet:

Host 192.168.0.*
    StrictHostKeyChecking no
    UserKnownHostsFile=/dev/null

I hope this helps someone else who runs into this issue.

like image 32
Iwnnay Avatar answered Nov 09 '22 08:11

Iwnnay