This command works fine for me with password-less ssh:

rsync -aqve ssh ${user}@${remote_host}:/etc/bind /tmp/etc/bind

Since I would like to rsync directly to my own local /etc/bind with root permissions, I tried:

sudo rsync -aqve ssh ${user}@${remote_host}:/etc/bind /etc/bind

But now, I get a password prompt (this is bad).

How do I fix this line to copy directly to my local /etc/bind without a password prompt?


When you do this with your own user, you're using the SSH keys in your own $HOME/.ssh/ directory. When you're doing it as root using sudo, ssh will look in root's home directory for the .ssh directory - and your keys aren't there.

Here are four ways to fix this - any one of them should work:

  1. As root, create new ssh keys for and add the public part to the authorized_keys for your user on the remote server
  2. Copy your own SSH keys to root's .ssh directory. (Make sure you don't overwrite any existing keys!)
  3. Give your own user write access to the target directory. Consider the security implications before choosing this method!
  4. As Chris Down says, use your existing SSH keys by using the command

    $ sudo rsync -aqve 'ssh -i ~user/.ssh/id_rsa' \
         ${user}@${remote_host}:/etc/bind /etc/bind
| improve this answer | |
  • 5
    Another option is to use rsync -e 'ssh -i ~user/.ssh/id_rsa' [...], or similar. This avoids having to copy the key over. – Chris Down Jun 5 '14 at 12:34
  • 1
    Chris Down's idea is better, I've added it. – Jenny D Jun 5 '14 at 12:38

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.