Specify identity file (id_rsa) with rsync

You can specify the exact ssh command via the '-e' option:

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 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.

This can be done with SSH user config see: http://www.cyberciti.biz/faq/create-ssh-config-file-on-linux-unix/ basically edit ~/.ssh/config:

$ nano ~/.ssh/config
#Add Hosts below 
Host server1
HostName examplehost.com
User username
Port 22
IdentityFile /path/to/key

$ rsync -e ssh /home/user/directory [email protected]:home/user/directory/

This should work for any program using SSH, rsync,

For me it was sufficient to start the ssh-agent as follows:

eval `ssh-agent -s`
ssh-add /path/to/mykey

See also a longer answer here https://stackoverflow.com/questions/17846529/could-not-open-a-connection-to-your-authentication-agent