Repository navigation
Open
Labels
Description
Are you using paramiko as a client or server?
Both
What feature(s) aren't working right?
Keys/auth
What version(s) of paramiko are you using?
5.0.0
What version(s) of Python are you using?
3.13.15
What operating system and version are you using?
Rocky Linux 8.10
If you're connecting as a client, which SSH server are you connecting to?
No response
If you're using paramiko as part of another tool, which tool/version?
No response
Expected/desired behavior
Paramiko to write an Ed25519Key to a file.
Actual behavior
Fails with the following error
Traceback (most recent call last):
File "tst.py", line 17, in <module>
paramiko_key.write_private_key_file("test")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
File ".pixi/envs/dev/lib/python3.13/site-packages/paramiko/pkey.py", line 513, in write_private_key_file
self.private_key,
^^^^^^^^^^^^^^^^
AttributeError: 'Ed25519Key' object has no attribute 'private_key'. Did you mean: 'from_private_key'?
How to reproduce
import paramiko
from cryptography.hazmat.primitives.asymmetric import ed25519
from cryptography.hazmat.primitives import serialization
import io
crypt_key = ed25519.Ed25519PrivateKey.generate()
crypt_bytes = crypt_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.OpenSSH,
encryption_algorithm=serialization.NoEncryption(),
)
paramiko_key = paramiko.Ed25519Key.from_private_key(io.StringIO(crypt_bytes.decode()))
paramiko_key.write_private_key_file("test")Anything else?
A workaround is swapping paramiko.Ed25519Key with this class
from typing import Optional
import paramiko.pkey
class FixedEd25519Key(paramiko.Ed25519Key):
@property
def private_key(self):
return ed25519.Ed25519PrivateKey.from_private_bytes(self._signing_key.encode())
def write_private_key_file(
self,
filename: str,
password: Optional[str] = None,
file_format: paramiko.pkey.FileFormat = paramiko.pkey.OPENSSH
):
super().write_private_key_file(filename, password, file_format)This adds the missing property and also changes the default file format to OPENSSH because PEM is not supported for that type of key.
Let me know if you find that useful, then I'll open a PR.
Activity
[-][BUG] - Error writing Ed25519Key[/-][+][BUG] - Error writing Ed25519Key to file[/+]Ed25519Key: add private_key, default to the OpenSSH format when writing