Reputation: 28489
I'm using paramiko to run some commands over ssh. I notice that paramiko takes 2-3 seconds to open a connection, while the command line ssh client is almost instant.
Using some prints, I've found that the sticking point is Transport.auth_publickey (it is using a discovered ~/.ssh/id_dsa). That's the same authentication method that command line ssh is using, so why might paramiko be running more slowly?
The code I'm using to connect is pretty simply:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('myhostname', **{'username': 'root'})
Upvotes: 2
Views: 1524
Reputation: 39548
This is most likely because the modular exponentiation operations needed both for the Diffie-Hellman key-exchange and the RSA public key authentication are orders of magnitude slower in a Python bytecode interpreter (as in pure Python Paramiko) compared to heavily optimized compiled native binary that OpenSSH uses.
Upvotes: 1