pythonsshparamikopageant

How to use Pageant with Paramiko on Windows?


I know that Paramiko supports Pageant under Windows, but it doesn't work by default.

I am looking for an example of connecting using the key that is loaded in Pageant.


Solution

  • This is what I am using to connect and do an automated login using Pageant to store my key, and connecting to it from within my Python script. It counts on Pageant already being loaded, (and I haven't found a good reliable way to launch it and load the key (prompt for key password)) but the below works for now.

    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()