1

I'm copying images from another PC every 3 hours. But recently I encountered an error. When I try to ssh to that PC I get this:

Unable to negotiate with 192.xxx.xx.xx port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1

I searched for a solution for this error and I found this:

-oKexAlgorithms=+diffie-hellman-group1-sha1

If I try to run that in the terminal with ssh, the error disappears, but I'm looking to have this work in a script. This is what I came up with:

sshpass -p ${pass} rsync -v --include="*/" --include="*.png" --exclude="*" --no-o --no-g --no-perms --omit-dir-times ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 ${usr}@${servip}:

But I got this errorP:

Unexpected remote arg: user@xxx.xxx.xx.xx:/home/nwpops/wrfcntl/plots/op01/20220419_0000/d01/f00000/pcpacc1h_mm.png
rsync error: syntax or usage error (code 1) at main.c(1372) [sender=3.1.3]

Any suggestion is appreciated.

BeastOfCaerbannog
  • 12,964
  • 10
  • 49
  • 77

1 Answers1

1

So I've been researching this for several days, since there are many different solutions floating around but none of them seemed to work in my automated rsync backup script for SlickStack.

This is the function I came up with ultimately:

function ss_rsync_backup {
    rsync -acz --mkpath --rsh="sshpass -p ${RSYNC_PASSWORD} ssh -o StrictHostKeyChecking=no -l ${RSYNC_USER}" "$@"
}

And then use like this:

ss_rsync_backup /var/www/html/ "${RSYNC_USER}"@"${RSYNC_REMOTE_HOST}":slickstack/"${SITE_DOMAIN_EXCLUDING_WWW}"/html/

It's actually kind of insane how sensitive and complex the rsync command syntax is... I think they are kind of stuck with regard to backwards compatibility, so it is what it is.

Unlike other Linux utilities, if you are browsing various options/flags on StackOverflow and trying to combine them it might break things... the formatting of the syntax is very important.

Also be sure to apt install sshpass before use this script.

Note: you should NOT requrie the -e flag if you are using the formatting I used above.

Thanks: https://itecnote.com/tecnote/r-how-to-pass-password-automatically-for-rsync-ssh-command/

Jesse Nickles
  • 440
  • 4
  • 12