Rsync deleted files via ssh to my local machine using sudo privileges on the local side and my ssh private key

I want to synchronize a directory /var/sites/example.net/from a remote computer to a directory in the same path on my local computer.

The remote computer only authenticates SSH connections with keys, not passwords.

On my local machine, I have an alias set to ~ / .ssh / config, so that I can easily run ssh myserverto login.

I try rsync -a myserver:/var/sites/example.net/ /var/sites/example.net/, but it fails because my local user does not have permission to edit the local directory /var/sites/example.net/.

If I try sudo rsync -a myserver:/var/sites/example.net/ /var/sites/example.net/(just adding sudo), I can fix the local resolution problem, but then I came across another problem - my local root user does not see the correct ssh key or ssh alias.

Is there a way to perform this file synchronization by changing this rsync command? I would like to avoid changing anything else (e.g. no changes in perms or ssh settings)

+4
source share
3 answers

Try the following:

sudo rsync -e "sudo -u localuser ssh" -a myserver:/var/sites/example.net/ /var/sites/example.net/

rsync root, -e rsync ssh ( sudo -u localuser), ssh . Rsync - root, .

+8

larsks:

sudo rsync -e "sudo -u $USER ssh" ...

, rsync -a myserver:/var/sites/example.net/ /var/sites/example.net/ sudo rsync -e "sudo -u $USER ssh" -a myserver:/var/sites/example.net/ /var/sites/example.net/.

+1

:

sudo , sudoers sudo visudo NOPASSWD: rsync.

For details, you can consult with man sudoers.

this will work in any mode, even through cron, at, systemd.service + timer, etc.

test it with: ssh <user>@<your-server> "sudo <your-rsync-command>"

0
source

Source: https://habr.com/ru/post/1525878/


All Articles