I have this running on gitlab ci, and it works for regular ssh (copied from the gitlab ci docs):

eval $(ssh-agent -s)
ssh-add <(echo "$SSH_PRIVATE_KEY")
mkdir -p ~/.ssh
echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config

This gives me

Identity added: /dev/fd/63 (/dev/fd/63)

However, when I try to rsync I get an error:

Warning: Permanently added '*****' (ECDSA) to the list of known hosts.
Permission denied, please try again.
Permission denied, please try again.
user@server: Permission denied (publickey,password).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]

Why is rsync not able to use the identity added, when the ssh command is?

I can also do this instead, to work around the rsync issue.

eval $(ssh-agent -s)
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa

Which gives me

Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)

Which rsync is able to use, most likely because it's in the assumed place.

Does this mean rsync uses it's own ssh implementation and not the ssh-agent on the local system?


You can specify the ssh protocol with rsync using the "-e" option.

rsync -e ssh file.tmp example.com:~/

Identity could also be provided in that option.

rsync -e "ssh -i ~/.ssh/id_rsa" file.tmp exmple.com:~/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.