如何通过 ssh 正确使用从 WSL2 到远程 ubuntu EC2 服务器的 rsync

问题描述 投票:0回答:1

我在使用 rsync 将目录从 WSL2 复制到远程 ubuntu EC2 服务器时遇到问题。

在 WSL2 中,C 盘中有一个 test 文件夹,我从 WSL2 ubuntu 的 C 盘目录调用这些命令。 test文件夹里面有一个test.txt文件。

EC2 已开放为

0.0.0.0/0
--- ip 不是问题。

远程服务器 ssh 密钥有效,我可以进入并使用它。在远程服务器中,我从

test
目录创建了一个文件夹
~
。为了确定起见,也尝试使用其他目录。

我尝试过以下命令:

rsync -rv ./testfolder/ [email protected]:.~/test

结果

ssh: connect to host 000.00.00.000 port 22: Connection timed out
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(231) [sender=3.2.7]

rsync -avrzv --rsync-path "sudo rsync" -e "ssh -i ~/path.pem" ./testfolder/ [email protected]:~/test 

结果

ssh: connect to host 000.00.00.000 port 22: Connection timed out
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(231) [sender=3.2.7]

以下内容适用于守护进程,而不是 ssh,但无论如何都尝试过。

rsync -avrzv --rsync-path "sudo rsync" -e "ssh -i ~/path.pem" ./testfolder/ rsync://[email protected]:~/test

结果

ssh: connect to host 000.00.00.000 port 22: Connection timed out
rsync: did not see server greeting
rsync error: error starting client-server protocol (code 5) at main.c(1863) [sender=3.2.7]

对于端口22错误我根据一些文章做了以下操作:

步骤1:

systemctl list-unit-files |grep rsync
# this resulted in
rsync.service disabled enabled

第2步:

sudo systemctl enable rsync.service
# this resulted in
Synchronizing state of rsync.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable rsync

步骤3:

sudo systemctl start rsync.service
#this prints nothing but if i run Step 1 again...
systemctl list-unit-files |grep rsync
# this resulted in
rsync.service enabled enabled

执行此操作后,错误仍然存在。


我尝试添加

--timeout 9999
但错误仍然存在


运行时

ping 000.00.00.000
(使用 WSL2 cmd 中的远程 IP)

我明白了

PING 000.00.00.000 (000.00.00.000) 56(84) bytes of data. From 11.11.11.111 icmp_seq=166 Destination Net Unreachable


检查远程服务器上的端口

$ sudo lsof -i -P -n | grep LISTEN
systemd-r  305 systemd-resolve   14u  IPv4  16610      0t0  TCP 127.0.0.53:53 (LISTEN)
sshd       546            root    3u  IPv4  17881      0t0  TCP *:22 (LISTEN)
sshd       546            root    4u  IPv6  17896      0t0  TCP *:22 (LISTEN)
$ sudo ss -tulpn | grep LISTEN
tcp   LISTEN 0      128               0.0.0.0:22        0.0.0.0:*    users:(("sshd",pid=546,fd=3))
tcp   LISTEN 0      4096        127.0.0.53%lo:53        0.0.0.0:*    users:(("systemd-resolve",pid=305,fd=14))
tcp   LISTEN 0      128                  [::]:22           [::]:*    users:(("sshd",pid=546,fd=4))
$ sudo lsof -i:22
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sshd     546   root    3u  IPv4  xxxxx      0t0  TCP *:ssh (LISTEN)
sshd     546   root    4u  IPv6  xxxxx      0t0  TCP *:ssh (LISTEN)
sshd    2488   root    4u  IPv4  xxxxx      0t0  TCP ip-000-00-00-000.us-east-2.compute.internal:ssh->000.000.000.000.hwccustomers.com:00000 (ESTABLISHED)
sshd    2572 ubuntu    4u  IPv4  xxxxx      0t0  TCP ip-000-00-00-000.us-east-2.compute.internal:ssh->000.000.000.000.hwccustomers.com:00000 (ESTABLISHED)
$ sudo lsof -i -P -n
COMMAND    PID            USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd-n  303 systemd-network   15u  IPv4  xxxxx      0t0  UDP 172.00.00.00:00
systemd-r  305 systemd-resolve   13u  IPv4  xxxxx      0t0  UDP 127.0.0.00:53
systemd-r  305 systemd-resolve   14u  IPv4  xxxxx      0t0  TCP 127.0.0.00:53 (LISTEN)
chronyd    359         _chrony    5u  IPv4  xxxxx      0t0  UDP 127.0.0.0:000
chronyd    359         _chrony    6u  IPv6  xxxxx      0t0  UDP [::1]:323
sshd       546            root    3u  IPv4  xxxxx      0t0  TCP *:22 (LISTEN)
sshd       546            root    4u  IPv6  xxxxx      0t0  TCP *:22 (LISTEN)
sshd      2488            root    4u  IPv4  xxxxx      0t0  TCP xxx.xx.xx.xxx:22->jjj.jjj.jjj.jjj:60774 (ESTABLISHED)
sshd      2572          ubuntu    4u  IPv4  31800      0t0  TCP xxx.xx.xx.xxx:22->jjj.jjj.jjj.jjj:60774 (ESTABLISHED)

^ xxx.xx.xx.xxx 是远程服务器 ip,jjj.jjj.jjj.jjj 是我所在的 ip

$ sudo lsof -i -P -n | grep LISTEN
systemd-r  305 systemd-resolve   14u  IPv4  xxxxx      0t0  TCP 127.0.0.00:00 (LISTEN)
sshd       546            root    3u  IPv4  xxxxx      0t0  TCP *:22 (LISTEN)
sshd       546            root    4u  IPv6  xxxxx      0t0  TCP *:22 (LISTEN)

似乎每个教程都非常易于使用,他们运行它并且它有效。不确定我的电脑发生了什么,这使它无法工作

linux ssh remote-access rsync remote-server
1个回答
0
投票

很有趣,在我发布后 30 秒我尝试了这个并且它起作用了:

rsync -avrzv --rsync-path "sudo rsync" -e "ssh -i ~/location.pem" /directory/ ubunt[email protected]:~/remotedir --progress

因为我花了很长时间才弄清楚这一点,所以我将其保留在这里,除非模组想要删除!

© www.soinside.com 2019 - 2024. All rights reserved.