如何在Windows上使用Paramiko和Pageant?

6
我知道Paramiko支持Windows下的Pageant,但默认情况下它不起作用。
我正在寻找一个使用在Pageant中加载的密钥进行连接的示例。
1个回答

8

这是我使用的内容,通过Pageant存储我的密钥,自动登录并连接到其它设备,并在Python脚本中连接。这需要依赖于已经加载了Pageant(我还没有找到一个好的可靠方法来启动它和加载密钥(提示输入密码)),但以下内容目前可以使用。

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
host = 'somehost.com'
port = 22
ssh.connect(host, port=port,  username='user', allow_agent=True)
stdin,stdout,stderr = ssh.exec_command("ps -ef")
print stdout.read()
print stderr.read()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接