tags:

views:

450

answers:

1

I want to set up an automatic rsync job to backup a bunch of user accounts on my OS X machine to a linux fileserver. I have set up password-free ssh from my account to another machine, and it works great, so I tried using this command:

sudo rsync -avz /Users/jbloggs myserv:/var/Backup/

where myserv is an alias set up in my ~/.ssh/config. The problem I have is that I have to use sudo to get that command to work -- under my personal account I don't have access to the other users' home directories to copy files for backup. That command works fine on my own account without sudo, but when I run under sudo it's not looking at my ~/.ssh/config any more (so it complains about "unknown host myserv").

How can I get the rsync running under sudo to still look at my personal ~/.ssh/config?

Thanks!

+3  A: 

You can use

ssh -i /Users/myuser/.ssh/id_rsa -F /Users/myuser/.ssh/config login@host

to let ssh use your config / key files. Use "-v" to check which file it is using. You could also copy your configuration / id to /var/root/.ssh, which will be used by default when using ssh via sudo.

To pass these options to rsync, you have to set the "--rsh" / "-e" like this:

rsync -e "ssh -i ... -F ..."
VolkA
Cool, thanks for that. In the general case (if this wasn't a home computer) then copying my ssh_config over to /var/root would be a security hole, no? It means that anyone with sudo access could connect to the remote host using that config?
Stewart Johnson
Well, the security hole is inherent, since you want to batch-copy files to the remote computer and use an unencrypted private key for that. Anyone with sudo access to a computer where your unencrypted key is stored will be able to ssh into the remote pc. (And with some work also the encrypted key)
VolkA
So the best way to go is to generate a new key which only has access to the backup account - so in case your key gets lost only this account is compromised.
VolkA