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:
- As root, create new ssh keys for and add the public part to the
authorized_keys
for your user on the remote server - Copy your own SSH keys to root's
.ssh
directory. (Make sure you don't overwrite any existing keys!) - Give your own user write access to the target directory. Consider the security implications before choosing this method!
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
Related videos on Youtube
Author by
kfmfe04
Updated on September 18, 2022Comments
-
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 almost 10 yearsAnother option is to use
rsync -e 'ssh -i ~user/.ssh/id_rsa' [...]
, or similar. This avoids having to copy the key over. -
Jenny D almost 10 yearsChris Down's idea is better, I've added it.