我已经用pexpect编写了一个脚本,我可以在其中使用ssh登录,但有时在某些服务器上我得到:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
3d:1b:02:9e:b2:b8:f0:f7:c6:4f:94:96:f6:e3:c0:d1.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:8
RSA host key for 10.10.10.69 has changed and you have requested strict checking.Host key verification failed.还有剧本刹车。
我知道,可以使用以下方法传递此警告:
os.system('ssh-keygen -f "/home/alex/.ssh/known_hosts" -R %s' % (ip))这是我的密码:
from pexpect import pxssh
try:
s = pxssh.pxssh()
s.login(ip, user, password)如何让登录输出检查输出是否包含WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED,以便我可以使用上面的命令。
发布于 2018-01-26 10:45:57
来自期望值文档
给予expect()的模式可能是正则表达式,也可能是正则表达式的列表。这允许您匹配多个可选响应。expect()方法返回匹配模式的索引。
所以,你可以这样做:
pattern_index = server.expect(["WARNING:", "Normal response"])
if pattern_index == 0:
#handle the warning message
else:
server.sendline(....)
server.expect(....)https://stackoverflow.com/questions/48459638
复制相似问题