如何检查主机是否在您的known_host ssh中 [英] how to check if a host is in your known_host ssh
本文介绍了如何检查主机是否在您的known_host ssh中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在脚本中执行以下命令,该命令将主机添加到ssh中的已知主机.
I have the following command works in my script that adds the host to the known hosts in ssh.
VAR2=$(expect -c '
spawn ssh -o StrictHostKeyChecking=no '"$REMOTE_HOST_USER@$REMOTE_HOST_IP"'
expect "*?assword:*"
send "'"$REMOTE_HOST_PASSWD"'\r"
expect {
"Permission denied, please try again." {
exit '"$WRONG_PASSWORD"'
}
}
')
工作正常,但是如果主机已经在known_hosts中,则我需要在命令之前进行控制,如果主机已经在known_hosts中,则不执行命令.如何检查主机是否在known_hosts中?
Works fine, but I need to control before the command if the host is already in known_hosts and not execute command if it is already in known_hosts. How can i check if an host is in known_hosts?
推荐答案
尝试: ssh-keygen -F< hostname>
如果找到主机名指纹并且命令返回 0
,则将显示 known_hosts
行,否则不显示任何内容,并且命令返回 1
.
Will show the known_hosts
line(s) if the hostname fingerprint is found and the command returns 0
, otherwise nothing is shown and the command returns 1
.
这篇关于如何检查主机是否在您的known_host ssh中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文