I need to make periodic backups of a directory on a remote server which is a virtual machine hosted by a research organisation They mandate that access to vms is through ssh keys, which is all good, except that i can't figure out how to point rsync to the ssh key for this server.
Rsync has no problem if the key file is
~/.ssh/id_rsa , but when it is something else I get
Permission denied (publickey) .
With ssh I can specify the identity file with
-i , but rsync appears to have no such option.
I have also tried temporarily moving the key on the local machine to
~/.ssh/id_rsa , but that similarly does not work.
Is there any way to specify an identity file with rsync?
You can specify the exact ssh command via the option -e
rsync -Pav -e "ssh -i $HOME/.ssh/somekey" username@hostname:/from/dir/ /to/dir/
Many ssh users are unfamiliar with their ~/.ssh/config file. You can specify the default settings per host via the config file
Host hostname User username IdentityFile ~/.ssh/somekey
In the long run it is best to learn the ~/.ssh/config file.