I'm trying to use a keypair for the SSH connection to an SFTP server.
I am able to do so if I generate an RSA key via ssh-keygen -t rsa
.
When I connect to the server via Paramiko, things work fine:
private_key = paramiko.RSAKey.from_private_key_file("/path/to/my/private/key")
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print("Connecting.")
client.connect(hostname="host.sftp.com", username="user", pkey=private_key)
print("Connected.")
However, if I try to do this with a ED25519 key, I get the below error:
ssh-keygen -t ed25519
File "/usr/local/lib/python3.7/site-packages/paramiko/pkey.py", line 235, in from_private_key_file
key = cls(filename=filename, password=password)
File "/usr/local/lib/python3.7/site-packages/paramiko/rsakey.py", line 55, in __init__
self._from_private_key_file(filename, password)
File "/usr/local/lib/python3.7/site-packages/paramiko/rsakey.py", line 176, in _from_private_key_file
self._decode_key(data)
File "/usr/local/lib/python3.7/site-packages/paramiko/rsakey.py", line 192, in _decode_key
n, e, d, iqmp, q, p = self._uint32_cstruct_unpack(data, "iiiiii")
File "/usr/local/lib/python3.7/site-packages/paramiko/pkey.py", line 529, in _uint32_cstruct_unpack
raise SSHException(str(e))
paramiko.ssh_exception.SSHException: unpack requires a buffer of 4 bytes
I'm a bit at a loss here since googling around doesn't seem to yield any relevant solutions. Is this a bug within paramiko
? It is an issue with how I am initializing my SSHClient
? Or is it actually a theoretical issue (ie. the way ED25519 creates the key, it is not possible to read in via the low-level unpack()
call)?
This is Dave Thompson's comment as an answer to just close the loop on this:
paramiko.RSAKey.from_private_key_file
reads RSA keys. To read an Ed25519 key use paramiko.Ed25519Key.from_private_key_file
. (And at least 2.2.0.)