Paramiko can’t find keys from ssh-agent on Windows

I am trying to connect to a test device on my local network using paramiko and SSH. If I specify the filename of my key and its passphrase, I can connect to the device without a problem. However, since my script is meant to run on any machine that has the key added to the ssh-agent, I am trying to find a way around that.

ssh-add -l shows me that the key is active in my ssh-agent, but if I use the get_keys() method from the paramiko.Agent-class, there’s just an empty list, meaning to me that Paramiko either can’t connect to the ssh-agent or doesn’t have the permissions to get the keys.

From shell, I can just connect to the device with ssh root@IPADDRESS. When I try to connect to device with Paramiko without specifying the path to the key and its passphrase, I’m just getting the “Authentication failed” error.

import paramiko
import os

def createSSHClient(server, port, user):
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(server, port, username=user)
    return client

ssh = createSSHClient('IPADDRESS', 22, 'root')

Checking SSH_AUTH_SOCK in os.environ gives me back False, but as far as I know, SSH on Windows doesn’t quite work like on Unix/Linux.

Answer

Paramiko cannot talk to OpenSSH ssh-agent on Windows.

It can talk to PuTTY Pageant only.