Here is what worked for me, considering that I want to keep password authentication (so I don't want to use NOPASSWD
or keys) - on Ubuntu 14.04:
- "Open up"
sudo
on remote machine by disabling tty_tickets
through a temporary file in /etc/sudoers.d/
(which should be supported on Debian, see /etc/sudoers.d/README
), and "Update the user's cached credentials", which "extends the sudo timeout for another 15 minutes"
- Run the
rsync
with sudo
as shown in other answers
- "Close down"
sudo
on remote machine by removing the temporary file in /etc/sudoers.d/
, which re-enables tty_tickets
... or, with command lines:
ssh -t $REMOTEPC 'echo "Defaults !tty_tickets" | sudo tee /etc/sudoers.d/temp; sudo -v'
rsync -aP -e 'ssh' '--rsync-path=sudo rsync' /etc/pulse/client.conf $REMOTEPC:/etc/pulse/client-copy.conf
ssh -t $REMOTEPC 'sudo rm -v /etc/sudoers.d/temp; sudo -v'
These are the responses I get when running these commands on the local machine:
$ ssh -t $REMOTEPC 'echo "Defaults !tty_tickets" | sudo tee /etc/sudoers.d/temp; sudo -v'
remoteuser@$REMOTEPC's password:
[sudo] password for remoteuser:
Defaults !tty_tickets
Connection to $REMOTEPC closed.
$ rsync -aP -e 'ssh' '--rsync-path=sudo rsync' /etc/pulse/client.conf $REMOTEPC:/etc/pulse/client-copy.conf
remoteuser@$REMOTEPC's password:
sending incremental file list
client.conf
1269 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/1)
$ ssh -t $REMOTEPC 'sudo rm -v /etc/sudoers.d/temp; sudo -v'
remoteuser@$REMOTEPC's password:
removed ‘/etc/sudoers.d/temp’
[sudo] password for remoteuser:
Connection to $REMOTEPC closed.
Note that sudo -v
should be ran after each time files in /etc/sudoers.d/
, so the changes therein are accepted.