The authenticity of host '10.4.111.1 (10.4.111.1)' can't be established.
ECDSA key fingerprint is SHA256:S1VBZZWcIFk1B1dfasDFfwgU2LN1f9WX4gynfkivTsGsU.
ECDSA key fingerprint is MD5:eb:9e:4d:ad:e8:f2:fe:f5:a2:ea:15:1b:9a:7d:6d:93.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.4.111.1' (ECDSA) to the list of known hosts.

因为要通过sshpass批量去远程执行命令,所以每一次都弹出这个很麻烦。

解决办法 :

#首先备份 ssh 配置文件
~]# cp /etc/ssh/ssh_config /etc/ssh/ssh_config_bak

将配置文件中的 StrictHostKeyChecking ask改为 StrictHostKeyChecking noGSSAPIAuthentication yes 改为 GSSAPIAuthentication no

Host *
        GSSAPIAuthentication no
        StrictHostKeyChecking no

然后再执行批量的sshpass批量命令就虽然会有提示,但是可以正常执行。

~]# sshpass -p NwV7abcdefg  ssh cachecloud@10.4.111.1 "ps -ef | grep redis-server | grep -v 'grep' | awk '{print $9}' | awk -F ':' '{print $2}'"      >> redis-server.txt

Warning: Permanently added '10.4.111.1' (ECDSA) to the list of known hosts.

另外,如果使用sshpass执行命令但没有返回,可以先把ssh执行的部分拿出来单独执行,可以看出具体未执行的原因是什么,比如我这个就是因为提示了The authenticity of host '10.4.111.1 (10.4.111.1)' can't be established.的原因无法继续执行。

参考文档:https://www.cnblogs.com/iHey/p/15203985.html

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐