Error copying files between servers

Asked

Viewed 405 times

0

I am copying files via rsync between two linux servers, the command I am using is:

rsync -Cravzpt --remove-source-files --exclude 'script.sh' --exclude 'index.php' /var/www/html/bkpserver/tarefario [email protected]:/var/www/html/

But when I run this command, it asks root password and after a few seconds, it shows the following error:

ssh: connect to host xxx.xxx.xxx.xxx port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [sender] 
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]

I have no idea why you are having this error, because I have exactly the same command on 3 more different servers and copying to the same target server and they all work.

  • This question is not about programming. There must be another OS community that there with that.

  • @Thiagolunardi The question is not of programming.

  • @Thiagolunardi Dei o enter antes da hora, The question is not specifically about programming but is about Ubuntu servers. I think it’s in the scope.

  • There is Server fault Stack Exchange

  • @Thiagolunardi So tell me, what kind of question can be asked in these tags that he flagged? Ubuntu and Server. Well, Ora. :-)

2 answers

1

The error message says that the server refused the connection, it could be a blocking firewall, a router in the middle of the connection or the closed ssh port 22. Try the following (examples here presupposes debian or Ubuntu):

1) See if the ssh service is active

$ sudo /etc/init.d/ssh status
[sudo] senha para sidon: 
● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: active (running) since Qui 2017-07-20 08:27:25 BRT; 4h 36min ago
  Process: 1896 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
 Main PID: 1145 (sshd)
    Tasks: 1
   Memory: 1.4M
      CPU: 23ms
   CGroup: /system.slice/ssh.service
           └─1145 /usr/sbin/sshd -D

Watch the line Active: active (running)...

2) If running, check which door:

~$ sudo cat /etc/ssh/sshd_config | grep Port
Port 22

3) See if the door is open:

sudo netstat -pln | grep '22'
tcp        0      0 0.0.0.0:22          0.0.0.0:*           OUÇA   1145/sshd       
tcp6       0      0 :::22               :::*                OUÇA   1145/sshd        

Do this on the server side that is not accepting the connection.

If all this is ok (SSH active on port 22 open, no firewall blocking) see if the server is connected to a router, in which case the router works as, say... an intermediary or even a "firewall", then Voce needs to do a NAT redirection, that is when the rsync command requests port 22, the request "hits" the router and it does not know what to do, so you have to redirect 22 to the server ip.

  • Hello, @Sidon, sorry I didn’t give you a feedback earlier. I performed the tests you passed in this answer, the 3 items are ok. Both servers (source and destination) are hosted on Digitalocean and have no Firewall configuration beyond the standards of D.O itself.

  • I managed to make rsync run via direct command on Putty, but by the cron task remains the same problem.

0


I was unable to connect to the target server because the source server did not have an RSA key. I followed the tutorial "Generating the SSH keys and automating the access" that is found in the link: Remote backups with rsync and SSH keys and the backup started working normally.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.