sshpass scp失败问题记录

使用如下脚本编译程序和scp拷贝文件:

#!/bin/bash

cd `dirname $0`

# Build the project

bin_name="linux_cmd_web"

rm -f $bin_name

# gdb debug  x86
# g++ -I./c_src  -I./3rd  app.cpp  ota.cpp  log.cpp ./c_src/*.c  -o $bin_name -lpthread -g -O0 

export PATH=$PATH:~/workspace/project/rsu7012/toolchains/arm-linux-gnueabi/bin

# arch64
export PATH=~/genvict/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin:$PATH
# aarch64-linux-gnu-g++ -I./c_src  -I./3rd  -I./ ./c_src/*.c  ./3rd/*.cpp  ./*.cpp -o $bin_name -lpthread
# aarch64-linux-gnu-g++ -I./c_src    -I./ ./c_src/*.c  ./*.cpp -o $bin_name -lpthread
arm-linux-gnueabi-g++ -std=gnu++11 -I./c_src    -I./ ./c_src/*.c  ./*.cpp -o $bin_name -lpthread

if [ "$1" = "target" ]; then

    IP="192.169.5.169"
    # IP="192.168.4.204"
    echo $PWD
    sshpass -p "123456" ssh root@$IP "killall $bin_name"
    sshpass -p "123456" scp -O $bin_name root@$IP:/data
    if [ $? -ne 0 ]; then
        echo "scp $bin_name failed"
        exit 1
    fi
fi

if [ "$1" = "web" ]; then
    IP="192.169.5.169"
    sshpass -p "123456" scp -r www root@$IP:/genvict/
    sshpass -p "123456" scp websocket.conf root@$IP:/genvict/etc/lighttpd/conf.d/
fi

第一次执行报错:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ED25519 key sent by the remote host is
SHA256:U2j0+hwR5uhPV+Ev8MuaEgmGog7nIGEsJ5bM2yBYQVY.
Please contact your system administrator.
Add correct host key in /home/xgj/.ssh/known_hosts to get rid of this message.
Offending ED25519 key in /home/xgj/.ssh/known_hosts:14
  remove with:
  ssh-keygen -f "/home/xgj/.ssh/known_hosts" -R "192.169.5.169"
Host key for 192.169.5.169 has changed and you have requested strict checking.
Host key verification failed.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ED25519 key sent by the remote host is
SHA256:U2j0+hwR5uhPV+Ev8MuaEgmGog7nIGEsJ5bM2yBYQVY.
Please contact your system administrator.
Add correct host key in /home/xgj/.ssh/known_hosts to get rid of this message.
Offending ED25519 key in /home/xgj/.ssh/known_hosts:14
  remove with:
  ssh-keygen -f "/home/xgj/.ssh/known_hosts" -R "192.169.5.169"
Host key for 192.169.5.169 has changed and you have requested strict checking.
Host key verification failed.
lost connection
scp 19747bin_name failed

以前无法拷贝也是跟着提示执行ssh-keygen -f “/home/xgj/.ssh/known_hosts” -R “192.169.5.169”,在执行该语句后执行脚本还是出现sshpass scp传输文件失败问题。
但ssh可以登录,主机也能ping设备IP 192.169.5.169。

尝试不使用sshpass传输文件:

scp -r linux_cmd_web root@192.169.5.169:/root
The authenticity of host '192.169.5.169 (192.169.5.169)' can't be established.
ED25519 key fingerprint is SHA256:U2j0+hwR5uhPV+Ev8MuaEgmGog7nIGEsJ5bM2yBYQVY.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:3: [hashed name]
    ~/.ssh/known_hosts:10: [hashed name]
    ~/.ssh/known_hosts:11: [hashed name]
    ~/.ssh/known_hosts:12: [hashed name]
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.169.5.169' (ED25519) to the list of known hosts.
root@192.169.5.169's password: 
linux_cmd_web                                                       

传输成功。

执行 scp 命令时,SSH 客户端显示了一个关于主机身份验证的警告。这是因为 SSH客户端尝试连接到一个之前未曾连接过的主机,因此它无法验证该主机的真实性。当输入 “yes” 时,SSH 客户端会将该主机的公钥添加到known_hosts 文件中,这样以后连接时就不会再显示这个警告了。

尝试执行:

sshpass -p "123456" scp -O linux_cmd_web  root@192.169.5.169:/root

执行成功,再次执行脚本编译也编译成功。

第一次执行(手动输入密码):

scp -r linux_cmd_web root@192.169.5.169:/root

这次执行成功,手动确认了主机身份并输入了密码。

第二次执行(使用 sshpass):

sshpass -p "123456" scp -O linux_cmd_web root@192.169.5.169:/root

这次执行也成功了,且没有报错。

以下是可能的原因,为什么第二次执行成功了:

主机身份已知,由于第一次执行时您已经确认了主机身份,并将其添加到了 known_hosts 文件中,因此第二次执行时 SSH 客户端不再提示确认。

你可能感兴趣的:(Linux开发基础,疑难杂症,网络,sshpass,scp)