0

UPDATE:

it seems I have to use rsync modules. So I created a very simple rsyncd.conf in the home of user2 on the remote server with:

[test]
    path = /dest

It does not work, but the problem seems another one. When I run

rsync -e "ssh -v -l user1" --delete-after -aX  /src/* user2@remote_host::test

ssh connection is enstablished by user1 this time, but I get this error:

[...]
Bytes per second: sent 9093.3, received 12740.9
debug1: Exit status 1
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [sender=3.0.6]

rsync path on both servers is /usr/bin/rsync. What's the problem?


Question:

Scenario: I need to rsync to a remote server. I can login to the remote server using user1 (my personal user), but for doing anything else I have to change to user2 (the technical user). I can't ssh directly with user2 since I don't have its password, and there's too little free space on user1 home. I don't have free opened ports and the only sudo command I can launch with user1 is sudo su - user2. Furthermore, the source machine is identical to the remote one.

Question: Is there a way to rsync to a remote machine using user1 as the user that opens the ssh connection, and user2 as the user that runs the remote rsync?

I tried

rsync -e "ssh -l user1" --delete-after -aX  /src/* user2@remote_host:/dest

but it tries to use user2 as ssh user anyway.

With

rsync -e "ssh -l user2" --delete-after -aX  /src/* user1@remote_host:/dest

remote rsync uses user1 and it can't write on user2 dirs.

From man rsync:

USING RSYNC-DAEMON FEATURES VIA A REMOTE-SHELL CONNECTION
       It is sometimes useful to use various features of an rsync daemon 
       (such as named modules) without actually allowing  any  new  socket 
       connections into a system [...] Rsync supports connecting to a host 
       using a remote shell and then  spawning  a  single-use “daemon” 
       server that expects to read its config file in the home dir of the 
       remote user. [...]  since the daemon is started up fresh by the 
       remote  user,  you  may  not  be able to use features such as 
       chroot or change the uid used by the daemon. 

       [...]

       If  you  need to specify a different remote-shell user, keep in 
       mind that the user@ prefix in front of the host is specifying the 
       rsync-user value (for a module  that  requires  user-based  
       authentication).   This means  that you must give the ’-l user’ 
       option to ssh when specifying the remote-shell, as in this example
       that uses the short version of the --rsh option:

           rsync -av -e "ssh -l ssh-user" rsync-user@host::module /dest

       The “ssh-user” will be used at the ssh level; the “rsync-user” will 
       be used to log-in to the “module”.

I feel like I'm not understanding something "under the hood".

Marco Sulla
  • 207
  • 2
  • 4
  • 15
  • Can't you initiate the `rsync` from the remote site when switched to `user2`? After all, `rsync` can work in both directions. – Sven Jul 17 '15 at 13:16
  • Well, unluckily no. "Local" machine have the same problems of the "remote" one. I updated the question. – Marco Sulla Jul 17 '15 at 13:21
  • 1
    Then see that you get necessary permissions to do your work. – Sven Jul 17 '15 at 13:22
  • @Sven: It's impossible. Servers are provided by third party, so any additional requests costs money to my company. Once the system is set up, it's nearly impossible that someone will add me additional packages, grants or anything else. It's my fault, I do not prevented this problem. – Marco Sulla Jul 17 '15 at 13:29

1 Answers1

0

UPDATE:

Maybe it's possible using --rsync-path="sudo su -l user2 -c rsync" or --rsync-path="sudo -u user2 rsync"? I'll try monday.


ANSWER:

Ok, it seems it's not possible. Any workaround with other methods/tools are welcome.

The last solution I found is to have an rsync.conf file under user1 home like this:

[iog]
    path = /dest

and run from local server:

rsync -v --rsync-path="rsync --log-file=/tmp/rlog --config=/home/user1/rsync.conf"  \
      -e "ssh -v -l user1" --delete-after -aX /src/* user2@host::test

The error returned is

debug1: Sending command: rsync --log-file=/tmp/rlog --config=/home/user1/rsync.conf \
                               --server --daemon .
@ERROR: chroot failed

From man rsync:

USING RSYNC-DAEMON FEATURES VIA A REMOTE-SHELL CONNECTION
       [...] since the daemon is started up fresh by the 
       remote  user,  you  may  not  be able to use features such as 
       chroot or change the uid used by the daemon.

So it seems it's not possible to use rsync this way, under my conditions.

Marco Sulla
  • 207
  • 2
  • 4
  • 15