Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use an identity file with rsync?

Tags:

unix

rsa

rsync

dsa

People also ask

How do I use SSH key with rsync?

Using rsync With SSH and Your Key If you want details on what SSH is doing, add "-v" to the ssh options. To run rsync quietly, remove the "-v" option from both rsync and SSH option list. To reverse the synchronization so the remote file is updated on your local computer, reverse the source and destinations.

How do I transfer files using rsync?

If you want to copy a file from one location to another within your system, you can do so by typing rsync followed by the source file name and the destination directory. Note: Instead of “/home/tin/file1. txt”, we can also type “file1” as we are currently working in the home directory.

How do I rsync a directory in Linux?

You also have an empty directory called dir2 . To sync the contents of dir1 to dir2 on the same system, you will run rsync and use the -r flag, which stands for “recursive” and is necessary for directory syncing: rsync -r dir1/ dir2.


You may want to use ssh-agent and ssh-add to load the key into memory. ssh will try identities from ssh-agent automatically if it can find them. Commands would be

eval $(ssh-agent) # Create agent and environment variables
ssh-add ~/.ssh/1234-identity

ssh-agent is a user daemon which holds unencrypted ssh keys in memory. ssh finds it based on environment variables which ssh-agent outputs when run. Using eval to evaluate this output creates the environment variables. ssh-add is the command which manages the keys memory. The agent can be locked using ssh-add. A default lifetime for a key can be specified when ssh-agent is started, and or specified for a key when it is added.

You might also want to setup a ~/.ssh/config file to supply the port and key definition. (See `man ssh_config for more options.)

host 22.33.44.55
    IdentityFile ~/.ssh/1234-identity
    Port 1234

Single quoting the ssh command will prevent shell expansion which is needed for ~ or $HOME. You could use the full or relative path to the key in single quotes.


Use either $HOME

rsync -avz -e "ssh -p1234  -i \"$HOME/.ssh/1234-identity\"" dir remoteUser@server:

or full path to the key:

rsync -avz -e "ssh -p1234  -i /home/username/.ssh/1234-identity" dir user@server:

Tested with rsync 3.0.9 on Ubuntu


You have to specify the absolute path to your identity key file. This probably some sort of quirck in rsync. (it can't be perfect after all)

I ran into this issue just a few days ago :-)


This works for me

rsync -avz --rsh="ssh -p1234  -i ~/.ssh/1234-identity"  \
"/local/dir/" [email protected]:"/remote/dir/"

use key file with rsync:

rsync -rave "ssh -i /home/test/pkey_new.pem" /var/www/test/ [email protected]:/var/www/test