ssh远程执行命令出现「Are you sure you want to continue connecting (yes/no)?」解决方法
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 no
,GSSAPIAuthentication 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.
的原因无法继续执行。