pexpect 登陆ssh遇到个问题及解决

本文发布时间: 2019-Mar-21
pexpect 登陆ssh,The authenticity of host '69.28.52.37 (69.28.52.37)' can't be established.RSA key fingerprint is d2:98:ec:00:06:61:e0:aa:14:e8:53:84:8a:cc:14:a6.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '69.28.52.37' (RSA) to the list of known hosts.由于多了"Warning: Permanently added '69.28.52.37' (RSA) to the list of known hosts."这里卡住,设置pexpect 超时时间没用sh = pexpect.spawn('ssh -p %s %s@%s "%s"'%(port,user, ip, cmd),timeout=None)r = '' try: i = ssh.expect(['password: ', 'continue connecting (yes/no)?'],) #print "i为",i if i == 0 : ssh.sendline(passwd) ssh.sendline('\n') elif i == 1: ssh.sendline('yes \n') print ssh.before,ssh.after except pexpect.EOF,pexpect.TIMEOUT: print ssh.before,ssh.after ssh.close() else: r = ssh.read() ssh.expect(pexpect.EOF) print ssh.before,ssh.after ssh.close()终于在网上找到类似解决办法ssh = pexpect.spawn('ssh -oStrictHostKeyChecking=no -n -p %s %s@%s "%s"'%(port,user, ip, cmd),timeout=120)加了 "ssh -oStrictHostKeyChecking=no",用来避免 输入第一次 执行ssh 要求收入yes/no 用的。


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:08pm
栏目列表