0
votes

What's wrong with this code?

sudo -u replicant rsync -av -e "ssh -o 'StrictHostKeyChecking no' -i /home/replicant/.ssh/id_rsa" --exclude 'media/' --exclude 'var/' --exclude '.svn' root@$ADMIN:/var/www/ /var/www/ &> /tmp/rsync
if
[ $? -ne 0 ]; then
echo "date: Error rsync'ing code base from $ADMIN check /tmp/rsync" | mail -s "Rsync error!" $DEVEMAIL
echo "date: Error rsync'ing code base from $ADMIN check /tmp/rsync" >> $LOGFILE
echo "root@$ADMIN:/var/www /var/www" >> $LOGFILE
exit
fi

I keep getting this error:

Permission denied (publickey).
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(605)
[Receiver=3.0.9]

Please help. Thanks.

1
Late reply, but it sounds like your SSH key was not accepted by the remote server, check it's the right public key and that it's readable by the replicant user - Jamie Taylor

1 Answers

0
votes

Try to login directly on SSH to fix your issues, then move on to your rsync test. So start with:

ssh -o 'StrictHostKeyChecking no' -i /home/replicant/.ssh/id_rsa root@$ADMIN

Sidenotes:

  • don't use root for such a task
  • add set -eu at the start of your Bash script, so that errors will end up your script and ease debugging (for example if $ADMIN is not defined, the script will end in error)