如何使用 Python 将主机名添加到 known_hosts? [英] How to add hostname to known_hosts using Python?

查看:39
本文介绍了如何使用 Python 将主机名添加到 known_hosts?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码将服务器添加到 known_hosts:

I am using this code to add server to the known_hosts:

subprocess.Popen(['sshpass', '-p', password, 'ssh', '-o', 'StrictHostKeyChecking=no', add_key], stdout=subprocess.PIPE).communicate()[0]

这将主机名添加到 known_hosts,但服务器在尝试进入主机时挂起.我只想将主机名添加到 known_hosts 并继续我的其他代码.我怎样才能做到这一点?谢谢

This adds hostname to the known_hosts but the server hangs as it tries to enter into the host. I just want add hostname to the known_hosts and continue with my other codes. How can I do that? Thanks

推荐答案

没关系,自己解决了.这是我所做的:

Never mind, Solved it myself. Here's what I did:

test = subprocess.Popen(['sshpass', '-p', password, 'ssh', '-o', 'StrictHostKeyChecking=no', add_key])
            time.sleep(5.0)
            test.kill()

谢谢!

这篇关于如何使用 Python 将主机名添加到 known_hosts?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆