10

On my linux server I run the command:

sshpass -p 'password' rsync -avz /source/folder/ root@192.168.x.x:/dest/folder

When I run the command without sshpass it will provide me with prompts for authenticity of host and the password.

I need some equivalent to "-o StrictHostKeyChecking=no" (which I use for ssh) that will allow me to run this with no prompts or errors.

Everything I saw from googling was about ssh throwing the error not rsync.

khm
  • 466
  • 2
  • 4
  • 17

4 Answers4

23

If you want to connect to new server, which public key is not yet in your ~/.ssh/knonwn_hosts, you should not skip this only security check, but rather store the server host key in the known_hosts manually, verify that it is correct and then make the automatic check working.

Simplest way to get the known hosts populated with the server host key is using

ssh-keyscan server-ip >> ~/.ssh/known_hosts

After that, you should not need to use the StrictHostKeyChecking=no workaround.

Jakuje
  • 24,773
  • 12
  • 69
  • 75
  • 2
    For those running SSH on non-standard port, the cmd should be: `ssh-keyscan -p port server-ip >> ~/.ssh/known_hosts` – Henry Luo Mar 19 '20 at 08:09
9

This is the right command without output errors:

sshpass -p "yourpassword" rsync -rvz -e 'ssh -o StrictHostKeyChecking=no -p 22' --progress  root@111.111.111.111:/backup/origin /backup/destination/
6

I found the following command at cyberciti. This allowed me to do exactly what I needed.

$ rsync --rsh="sshpass -p myPassword ssh -o StrictHostKeyChecking=no -l username" server.example.com:/var/www/html/ /backup/

Jakuje
  • 24,773
  • 12
  • 69
  • 75
khm
  • 466
  • 2
  • 4
  • 17
  • 2
    That is very bad practice to skip the only check that prevents you from malicious attackers getting between you and you server and stealing your passwords, listen to whatever you transfer and potentially modify that. – Jakuje Jun 04 '17 at 09:04
  • 3
    I don't care about that. My server and it's entire network is physically enclosed in a secured room. – khm Jun 05 '17 at 13:36
  • 1
    Bypassing security checks - the **only** check that was used in your case - should **never** be the solution. And it should **never** be the accepted answer. It may be the *solution* to your specific problem and you accept the risk in your case, but that doesn't mean it's the best solution for everyone else. I encourage you to rethink your "accepted answer". – eDonkey Nov 03 '22 at 10:11
1

In some cases sshpass attempts find "assword" as the default password prompt indicator. But rsync can return similar string:

Enter passphrase for key '/home/user/.ssh/private_user_key':

So, try to add '-P' parameter:

sshpass -p "yourpassword" -P 'Enter passphrase for key' rsync 111.111.111.111:/backup/origin /backup/destination/

Path to your private key you can set in /home/user/config or set with -e parameter like that:

sshpass -p "yourpassword" -P 'Enter passphrase for key' rsync -e 'ssh -i /home/user/.ssh/private_user_key' 111.111.111.111:/backup/origin /backup/destination/

More inf about default password prompt indicator:

$ sshpass -V
sshpass 1.06
(C) 2006-2011 Lingnu Open Source Consulting Ltd.
(C) 2015-2016 Shachar Shemesh
This program is free software, and can be distributed under the terms of the GPL
See the COPYING file for more information.

Using "assword" as the default password prompt indicator.
pic0
  • 491
  • 1
  • 6
  • 15
  • After bouncing around the web trying to figure out my issue, this `-P 'Enter passphrase for key'` solved my connection issues. Thank you. – theOneWhoKnocks Aug 12 '19 at 07:10