1

Two days ago I started using SSH to transfer backups of two Linux servers to another one. I created a shell script to run it in Crontab.

Both servers are using Ubuntu 14.04.5 LTS

My SQL-Server works fine, it does create a backup of the database, and then it runs the SSH script to send the file to the Backup Server.

Now, the Webpage Server it's the one I'm having problems with. The script works if I use it manually, but, in cron it doesn't work. I've even did backup of the .ssh folder, and did the exact same steps as the SQL-Server, and what it puts is

Host key verification failed.
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.0]

The backup script is as follows named backup.sh:

#!/bin/sh
/usr/bin/rsync -e 'ssh -i /home/hostUser/.ssh/id_rsa' -avzp --delete /path/folder/ userRemote@IP:/path/to/backup/

This is how I have my Cron task

00 00 * * * sh /home/hostUser/backup.sh >> /var/log/backup.log 2>&1

I generated the rsa key with

ssh-keygen -t rsa

Where I have to input to save the key.

The way I've made the conection is as follows:

ssh 'remoteUser@IP'

And copying the key with:

ssh-copy-id -i ~/.ssh/id_rsa.pub remoteUser@IP

I've done this steps in order for me to log in remotely. Using ssh -v userRemote@IP

OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to remoteUserIP [remoteUserIP] port 22.
debug1: Connection established.
debug1: identity file /home/hostUser/.ssh/id_rsa type 1
debug1: identity file /home/hostUser/.ssh/id_rsa-cert type -1
debug1: identity file /home/hostUser/.ssh/id_dsa type -1
debug1: identity file /home/hostUser/.ssh/id_dsa-cert type -1
debug1: identity file /home/hostUser/.ssh/id_ecdsa type -1
debug1: identity file /home/hostUser/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/hostUser/.ssh/id_ed25519 type -1
debug1: identity file /home/hostUser/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.10
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.10 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 73:de:35:34:54:46:00:f1:c6:1c:8e:bf:19:50:45:bc
debug1: Host 'remoteUserIP' is known and matches the ECDSA host key.
debug1: Found key in /home/hostUser/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/hostUser/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to remoteUserIP ([remoteUserIP]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = es_MX.UTF-8
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Fri Aug 17 10:38:39 CDT 2018

  System load:  0.0               Processes:          135
  Usage of /:   65.4% of 1.70TB   Users logged in:    0
  Memory usage: 19%               IP address for em1: remoteUserIP
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/

72 packages can be updated.
9 updates are security updates.

New release '16.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

*** Es necesario reiniciar el sistema ***
Last login: Fri Aug 17 10:37:18 2018 from hostUserIP

How can I make it to work, it's weird since I can make it to work on my SQL-Server.

Thanks in advance.

1 Answer 1

0

As the user running the backup;

ssh  -i /home/hostUser/.ssh/id_rsa 'remoteUser@IP'

This should ensure the ~/.ssh/known_hosts is updated with the rsa key of the server.

1
  • Thanks for your reply. I solved it by using the script with sudo, prompt me the password, and today, I saw that it backup files in the log! I don't know if this solution is the best, but it worked for me :S Aug 20, 2018 at 13:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .