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".
rsync
from the remote site when switched touser2
? After all,rsync
can work in both directions.