最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】rsync同步上传出错:Host key verification failed

Linux crifan 9339浏览 0评论

Makefile中rsync代码:

################################################################################

# Deploy to server

################################################################################

PASSWORD_FILE=sshpass_password.txt

REMOTE_USER=root

REMOTE_SERVER=xx.xx.xx.xx

REMOTE_PATH=/opt/cowfarm/farm_web/uapp

## copy generated build files to tmp folder

copy_build: create_folder_tmp

  cp -a $(BUILD_PATH)/* $(TMP_PATH)

## Deploy build files to remote server using rsync. create sshpass_password.txt file to contain password before use this

deploy: clean_tmp copy_build

  sshpass -f $(PASSWORD_FILE) rsync -avzh –progress –stats –delete –force $(TMP_PATH) $(REMOTE_USER)@$(REMOTE_SERVER):$(REMOTE_PATH)

运行出错:

➜  ucowsapp_h5 git:(master) ✗ make deploy

<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<——————————————————————————

Author  : crifan

Version : 20171222

Function: Auto deploy build files to remote server

Run ‘make help’ to see usage

<span style="font-size: 12px; color: rgb(51, 51, 51); font-family: Monaco;"–<——————————————————————————

rm -rf /Users/crifan/dev/dev_root/daryun/Projects/xxxxxx/sourcecode/ucowsapp/ucowsapp_h5/ucowsapp_h5/uapp

mkdir -p /Users/crifan/dev/dev_root/daryun/Projects/xxxxxx/sourcecode/ucowsapp/ucowsapp_h5/ucowsapp_h5/uapp

cp -a /Users/crifan/dev/dev_root/daryun/Projects/xxxxxx/sourcecode/ucowsapp/ucowsapp_h5/ucowsapp_h5/build/* /Users/crifan/dev/dev_root/daryun/Projects/xxxxxx/sourcecode/ucowsapp/ucowsapp_h5/ucowsapp_h5/uapp

sshpass -f sshpass_password.txt rsync -avzh –progress –stats –delete –force /Users/crifan/dev/dev_root/daryun/Projects/xxxxxx/sourcecode/ucowsapp/ucowsapp_h5/ucowsapp_h5/uapp [email protected]:/opt/cowfarm/farm_web/uapp

Host key verification failed.

rsync error: unexplained error (code 255) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-52/rsync/rsync.c(244) [sender=2.6.9]

make: *** [deploy] Error 6

但是对应账号,我通过SecureCRT中SSH2去登录,是可以正常用密码登录的。

rsync Host key verification failed

ssh – rsync Host key verification failed – Stack Overflow

猜测是和最近添加了

【已解决】生成SSH公钥私钥和用私钥登陆远程服务器

的问题,看来果然是啊

ssh – Host key verification failed [rsync: connection unexpectedly closed] – Server Fault

但是不对啊。应该自动判断host的IP不同,不实用本地的私钥的啊

Host key verification failed 的问题 · Issue #100 · meolu/walle-web

SSH connection problem with “Host key verification failed…” error – Ask Ubuntu

去看看:

~/.ssh/known_hosts

很明显,本地没有此处的主机42.123.xxx.xx啊

“ssh -o StrictHostKeyChecking=no [email protected] uptime”

Hosts key verification failed – RSync – openmediavault

“You can try -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null as parameters for rsync to switch off the host key check for your tests.”

问题之ssh中Host key verification failed的解决 – 倚楼听风雨 – SegmentFault

试试:

ssh -v [email protected]

然后输入yes,输入密码,可以登录。

➜  ucowsapp_h5 git:(master) ✗ ssh -v [email protected]

OpenSSH_7.6p1, LibreSSL 2.6.2

debug1: Reading configuration data /etc/ssh/ssh_config

debug1: /etc/ssh/ssh_config line 48: Applying options for *

debug1: Connecting to 42.123.xxx.xxx port 22.

debug1: Connection established.

debug1: identity file /Users/crifan/.ssh/id_rsa type 0

debug1: key_load_public: No such file or directory

debug1: identity file /Users/crifan/.ssh/id_rsa-cert type -1

debug1: key_load_public: No such file or directory

debug1: identity file /Users/crifan/.ssh/id_dsa type -1

debug1: key_load_public: No such file or directory

debug1: identity file /Users/crifan/.ssh/id_dsa-cert type -1

debug1: key_load_public: No such file or directory

debug1: identity file /Users/crifan/.ssh/id_ecdsa type -1

debug1: key_load_public: No such file or directory

debug1: identity file /Users/crifan/.ssh/id_ecdsa-cert type -1

debug1: key_load_public: No such file or directory

debug1: identity file /Users/crifan/.ssh/id_ed25519 type -1

debug1: key_load_public: No such file or directory

debug1: identity file /Users/crifan/.ssh/id_ed25519-cert type -1

debug1: Local version string SSH-2.0-OpenSSH_7.6

debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6

debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6 pat OpenSSH_6.6.1* compat 0x04000000

debug1: Authenticating to 42.123.xxx.xxx:22 as ‘root’

debug1: SSH2_MSG_KEXINIT sent

debug1: SSH2_MSG_KEXINIT received

debug1: kex: algorithm: [email protected]

debug1: kex: host key algorithm: ecdsa-sha2-nistp256

debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none

debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none

debug1: expecting SSH2_MSG_KEX_ECDH_REPLY

debug1: Server host key: ecdsa-sha2-nistp256 SHA256:+0KVfoF9chu2G5fnn1opudh3GMgAfBp0+h61L4pvz9I

The authenticity of host ‘42.123.xxx.xxx (42.123.xxx.xxx)’ can’t be established.

ECDSA key fingerprint is SHA256:+0KVfxxxxxx9I.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added ‘42.123.xxx.xxx’ (ECDSA) to the list of known hosts.

debug1: rekey after 134217728 blocks

debug1: SSH2_MSG_NEWKEYS sent

debug1: expecting SSH2_MSG_NEWKEYS

debug1: SSH2_MSG_NEWKEYS received

debug1: rekey after 134217728 blocks

debug1: SSH2_MSG_SERVICE_ACCEPT received

debug1: Authentications that can continue: publickey,password

debug1: Next authentication method: publickey

debug1: Offering public key: RSA SHA256:T9wlgAth8/bxxxxxufmcvl+NtHtHywMopw /Users/crifan/.ssh/id_rsa

debug1: Authentications that can continue: publickey,password

debug1: Trying private key: /Users/crifan/.ssh/id_dsa

debug1: Trying private key: /Users/crifan/.ssh/id_ecdsa

debug1: Trying private key: /Users/crifan/.ssh/id_ed25519

debug1: Next authentication method: password

[email protected]‘s password:

debug1: Authentication succeeded (password).

Authenticated to 42.123.xxx.xxx ([42.123.xxx.xxx]:22).

debug1: channel 0: new [client-session]

debug1: Requesting [email protected]

debug1: Entering interactive session.

debug1: pledge: network

debug1: Sending environment.

debug1: Sending env LANG = zh_CN.UTF-8

debug1: Sending env LC_CTYPE = zh_CN.UTF-8

Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.2.0-27-generic x86_64)

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

  System information as of Fri Dec 22 16:55:45 CST 2017

  System load:  0.0                Processes:           125

  Usage of /:   13.0% of 35.58GB   Users logged in:     1

  Memory usage: 32%                IP address for eth0: 192.168.1.32

  Swap usage:   0%

  Graph this data and manage this system at:

https://landscape.canonical.com/

New release ‘16.04.3 LTS’ available.

Run ‘do-release-upgrade’ to upgrade to it.

You have new mail.

Last login: Fri Dec 22 16:55:45 2017 from 180.117.242.79

_____________________________________________________________________

WARNING! Your environment specifies an invalid locale.

This can affect your user experience significantly, including the

ability to manage packages. You may install the locales by running:

   sudo apt-get install language-pack-zh

     or

   sudo locale-gen zh_CN.UTF-8

To see all available language packs, run:

   apt-cache search “^language-pack-[a-z][a-z]$”

To disable this message for all users, run:

   sudo touch /var/lib/cloud/instance/locale-check.skip

_____________________________________________________________________

root@ecs-e432-0002:~#

然后退出:

root@ecs-e432-0002:~# ^C

root@ecs-e432-0002:~# help

GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)

These shell commands are defined internally.  Type `help’ to see this list.

Type `help name’ to find out more about the function `name’.

Use `info bash’ to find out more about the shell in general.

Use `man -k’ or `info’ to find out more about commands not in this list.

A star (*) next to a name means that the command is disabled.

job_spec [&]                                                                history [-c] [-d offset] [n] or history -anrw [filename] or history -ps >

(( expression ))                                                            if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]… [ else >

. filename [arguments]                                                      jobs [-lnprs] [jobspec …] or jobs -x command [args]

:                                                                           kill [-s sigspec | -n signum | -sigspec] pid | jobspec … or kill -l [s>

[ arg… ]                                                                  let arg [arg …]

[[ expression ]]                                                            local [option] name[=value] …

alias [-p] [name[=value] … ]                                              logout [n]

bg [job_spec …]                                                           mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c>

bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq>  popd [-n] [+N | -N]

break [n]                                                                   printf [-v var] format [arguments]

builtin [shell-builtin [arg …]]                                           pushd [-n] [+N | -N | dir]

caller [expr]                                                               pwd [-LP]

case WORD in [PATTERN [| PATTERN]…) COMMANDS ;;]… esac                  read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p >

cd [-L|[-P [-e]] [-@]] [dir]                                                readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [>

command [-pVv] command [arg …]                                            readonly [-aAf] [name[=value] …] or readonly -p

compgen [-abcdefgjksuv] [-o option]  [-A action] [-G globpat] [-W wordlis>  return [n]

complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat]>  select NAME [in WORDS … ;] do COMMANDS; done

compopt [-o|+o option] [-DE] [name …]                                     set [-abefhkmnptuvxBCHP] [-o option-name] [–] [arg …]

continue [n]                                                                shift [n]

coproc [NAME] command [redirections]                                        shopt [-pqsu] [-o] [optname …]

declare [-aAfFgilnrtux] [-p] [name[=value] …]                             source filename [arguments]

dirs [-clpv] [+N] [-N]                                                      suspend [-f]

disown [-h] [-ar] [jobspec …]                                             test [expr]

echo [-neE] [arg …]                                                       time [-p] pipeline

enable [-a] [-dnps] [-f filename] [name …]                                times

eval [arg …]                                                              trap [-lp] [[arg] signal_spec …]

exec [-cl] [-a name] [command [arguments …]] [redirection …]            true

exit [n]                                                                    type [-afptP] name [name …]

export [-fn] [name[=value] …] or export -p                                typeset [-aAfFgilrtux] [-p] name[=value] …

false                                                                       ulimit [-SHabcdefilmnpqrstuvxT] [limit]

fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]            umask [-p] [-S] [mode]

fg [job_spec]                                                               unalias [-a] name [name …]

for NAME [in WORDS … ] ; do COMMANDS; done                                unset [-f] [-v] [-n] [name …]

for (( exp1; exp2; exp3 )); do COMMANDS; done                               until COMMANDS; do COMMANDS; done

function name { COMMANDS ; } or name () { COMMANDS ; }                      variables – Names and meanings of some shell variables

getopts optstring name [arg]                                                wait [-n] [id …]

hash [-lr] [-p pathname] [-dt] [name …]                                   while COMMANDS; do COMMANDS; done

help [-dms] [pattern …]                                                   { COMMANDS ; }

root@ecs-e432-0002:~# true

root@ecs-e432-0002:~# exitdebug1: client_input_channel_req: channel 0 rtype exit-status reply 0

debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0

logout

debug1: channel 0: free: client-session, nchannels 1

Connection to 42.123.123.254 closed.

Transferred: sent 3096, received 9948 bytes, in 121.7 seconds

Bytes per second: sent 25.4, received 81.8

debug1: Exit status 0

然后再去执行rsync调用ssh去上传文件,就可以了。

【总结】

此处rsync第一次调用ssh去上传同步文件到远程服务器,会报错:

Host key verification failed

原因:

好像是没有去ssh验证过,rsync无法识别?

总之,解决办法是:

命令行中去:

ssh -v [email protected]

然后对于:

Are you sure you want to continue connecting (yes/no)?

输入yes,会提示:

Warning: Permanently added ‘42.123.123.254’ (ECDSA) to the list of known hosts.

-》估计内部就是保存了密钥等信息,通过了服务器的ssh验证,本地保存了验证信息。

->接着输入密码,即可登录远程服务器。

->之后再去rsync调用ssh,就可以了。

转载请注明:在路上 » 【已解决】rsync同步上传出错:Host key verification failed

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.185 seconds, using 22.23MB memory