更新:

更新:

更新:

看来我必须使用 rsync 模块。因此,我在远程服务器上 user2 的主目录中创建了一个非常简单的 rsyncd.conf,其中包含以下内容:

[test]
    path = /dest

它不起作用,但问题似乎是另一个。当我运行

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

ssh 连接已建立用户1这次,但我收到了这个错误:

[...]
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 路径都是/usr/bin/rsync。有什么问题?


问题:

场景:我需要 rsync 到远程服务器。我可以使用 user1(我的个人用户)登录到远程服务器,但要执行其他任何操作,我必须更改为 user2(技术用户)。我无法直接使用 user2 进行 ssh,因为我没有它的密码,并且 user1 主目录中的可用空间太少。我没有可用的开放端口,我可以使用 user1 启动的唯一 sudo 命令是sudo su - user2。此外,源计算机与远程计算机完全相同。

问题:有没有办法使用 user1 作为打开 ssh 连接的用户,使用 user2 作为运行远程 rsync 的用户来 rsync 到远程机器?

我试过

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

但它还是会尝试使用 user2 作为 ssh 用户。

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

远程 rsync 使用用户 1,并且它无法在用户 2 目录上写入。

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”.

我感觉我似乎没有理解一些“幕后”的事情。

答案1

更新:

也许可以使用--rsync-path="sudo su -l user2 -c rsync"--rsync-path="sudo -u user2 rsync"?我会在周一尝试。


回答:

好吧,这似乎是不可能的。欢迎使用其他方法/工具来解决。

我发现的最后一个解决方案是将rsync.conf文件放在用户1像这样的家:

[iog]
    path = /dest

并从本地服务器运行:

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

返回的错误是

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

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.

因此,在我的条件下,似乎不可能以这种方式使用 rsync。

相关内容