首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >主机密钥验证SSH Rsync失败

主机密钥验证SSH Rsync失败
EN

Server Fault用户
提问于 2018-08-17 15:59:59
回答 1查看 2.9K关注 0票数 1

两天前,我开始使用SSH将两个Linux服务器的备份传输到另一个服务器。我创建了一个shell脚本来在Crontab中运行它。

两台服务器都在使用Ubuntu 14.04.5 LTS

我的Server工作正常,它确实创建了数据库的备份,然后运行SSH脚本将文件发送到备份服务器。

现在,网页服务器--这是我遇到问题的地方。如果我手动使用这个脚本,它就能工作,但是,在cron中它不起作用。我甚至备份了.ssh文件夹,并执行了与Server完全相同的步骤,以及它所放的内容

代码语言:javascript
运行
复制
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]

备份脚本如下所示,名为backup.sh:

代码语言:javascript
运行
复制
#!/bin/sh
/usr/bin/rsync -e 'ssh -i /home/hostUser/.ssh/id_rsa' -avzp --delete /path/folder/ userRemote@IP:/path/to/backup/

这就是我如何完成我的任务

代码语言:javascript
运行
复制
00 00 * * * sh /home/hostUser/backup.sh >> /var/log/backup.log 2>&1

生成rsa密钥的

代码语言:javascript
运行
复制
ssh-keygen -t rsa

我必须输入才能保存密钥。

我这样做的方式如下:

代码语言:javascript
运行
复制
ssh 'remoteUser@IP'

并使用以下内容复制密钥:

代码语言:javascript
运行
复制
ssh-copy-id -i ~/.ssh/id_rsa.pub remoteUser@IP

为了远程登录,我已经完成了这些步骤。使用ssh -v userRemote@IP

代码语言:javascript
运行
复制
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 hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com 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 no-more-sessions@openssh.com
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

我如何使它工作,这是奇怪的,因为我可以让它在我的Server上工作。

提前谢谢。

EN

回答 1

Server Fault用户

发布于 2018-08-19 03:04:16

作为运行备份的用户;

代码语言:javascript
运行
复制
ssh  -i /home/hostUser/.ssh/id_rsa 'remoteUser@IP'

这应该确保使用服务器的rsa键更新~/.ssh/known_hosts

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/926873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档