drop table
drop table

Reputation: 37

sudo rsync on target devices

Good morning,

I am currently having a problem that I cannot find the answer to on StackOverflow or google searches, and I have not yet solved.

I am trying to use rsync as a sudo user on a target device.

The issue:

What I've tried:

rsync -a --rsync-path "sudo rsync" USER@HOST:/root/FILE ./

Issue: "A terminal is required to read password"

ok, so let's try passing it through stdin

rsync -a --rsync-path "echo 'PASSWORD' | sudo -S rsync" USER@HOST:/root/FILE ./

rsync: connection unexpectedly closed (0 bytes received so far) [sender]

Issue: rsync error: error in rsync protocol data stream (code 12) at io.c(226) [sender=3.1.3]

rsync: connection unexpectedly closed (4 bytes received so far) [receiver]

rsync error: error in rsync protocol data stream (code 12) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-52.200.1/rsync/io.c(453) [receiver=2.6.9]

Do you guys have any other ideas about what I could be doing?

I am aware that echoing the password is not best practice, however I do not have many other options in the case that the server I am connecting to has not done a key exchange with root user and I cannot change the SUDOPASS settings.

In the end this is all getting plugged into a Python script, so if there is a better pythonic means of using rsync as a sudoer, please inform me.

Upvotes: 1

Views: 1623

Answers (1)

meuh
meuh

Reputation: 12255

If your remote sudo is configured so that once you have given the password, you do not need to give it again for a while, then you can try this:

rsync -a --rsync-path "echo 'PASSWORD' | sudo -S date >&/dev/null; sudo rsync" \
  USER@HOST:/root/FILE ./

To debug what command is being run on the remote add --debug=CMD2. If your remote does not understand the bash syntax >&/dev/null, use the longer >/dev/null 2>/dev/null.

Upvotes: 1

Related Questions