how to use rsync (using password-less ssh), with sudo just on the local side?

6,075

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
    
Share:
6,075

Related videos on Youtube

kfmfe04
Author by

kfmfe04

Updated on September 18, 2022

Comments

  • kfmfe04
    kfmfe04 over 1 year

    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?

  • clerksx
    clerksx almost 10 years
    Another option is to use rsync -e 'ssh -i ~user/.ssh/id_rsa' [...], or similar. This avoids having to copy the key over.
  • Jenny D
    Jenny D almost 10 years
    Chris Down's idea is better, I've added it.