linuxsshremote-accessrsyncremote-server

how to properly use rsync from WSL2 to remote ubuntu EC2 server via ssh


I'm having issues copying a directory from WSL2 to a remote ubuntu EC2 server using rsync.

In WSL2, there is a testfolder in the C drive and I'm calling these commands from the C drive directory from WSL2 ubuntu. testfolder has a test.txt file inside.

The EC2 is open as 0.0.0.0/0 --- ip isn't an issue.

The remote server ssh key works and I am able to get in and use it. In the remote server I created a folder test from the ~ directory. Tried using other directories as well just to be sure.

I have tried the following commands:

rsync -rv ./testfolder/ ubuntu@000.00.00.000:.~/test

Results:

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/ ubuntu@000.00.00.000:~/test

Results:

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]

The following is meant for a daemon, not ssh, but attempted anyway.

rsync -avrzv --rsync-path "sudo rsync" -e "ssh -i ~/path.pem" ./testfolder/ rsync://ubuntu@000.00.00.000:~/test

Results:

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]

For the port 22 error I did the following based on some articles:

Step 1:

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

Step 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

Step 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

After doing this the errors persist.


I attempted to add --timeout 9999 but errors persist


When running ping 000.00.00.000 (using remote IP from WSL2 cmd)

I get 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


Checking ports on remote server

$ 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)

^ the xxx.xx.xx.xxx is the remote server ip and the jjj.jjj.jjj.jjj is the ip im on

$ 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)

It seems like every tutorial makes it so easy to use, they run it and it works. Unsure what is going on through my computer thats not making it work


Solution

  • funny enough, 30 seconds after i posted i tried this and it worked; using the Public IPv4 DNS instead of the IP

    rsync -avrzv --rsync-path "sudo rsync" -e "ssh -i ~/location.pem" /directory/ ubuntu@ec0-00.us-west-1.compute.amazonaws.com:~/remotedir --progress
    

    Figured since it took me so long to figure this out ill keep this here unless mods want to delete!