You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement key formats and export file format function #96
I'd like to be able to choose the format of the key Im generating, for example: ssh-keygen -m PEM`, but I can't see how to do it on the library.
I was also trying other types of rsa keys (Maybe the default format would be the one I'm looking for), and it seems that they don't work:
Sorry if I wasn't clear when I opened the issue, but that enum if for the key type, not the key format, for example, using the terminal I can do this to generate a RSA key:
$ ssh-keygen -f test -t rsa
$ head test
-----BEGIN OPENSSH PRIVATE KEY-----
or
$ ssh-keygen -f test -t rsa -m PEM
$ head test
-----BEGIN RSA PRIVATE KEY-----
The key type is the same but the format is different.
-m Specify a key format for key generation, the -i (import), -e (export) conversion options, and the -p change passphrase operation. The latter may be used to convert between OpenSSH private key and PEM private key formats. The supported key formats are: “RFC4716” (RFC 4716/SSH2 public or private key), “PKCS8” (PKCS8 public or private key) or “PEM” (PEM public key). By default OpenSSH will write newly-generated private keys in its own format, but when converting public keys for export the default format is “RFC4716”. Setting a format of “PEM” when generating or updating a supported private key type will cause the key to be stored in the legacy PEM private key format.
Do we have a way how to choose a different key format? On the generate function we can only pass the bits and the key type, not the key format.
Activity
enkore commentedon Apr 25, 2025
That's basically just the wrapper for an enum, see examples/keygen.py for how to use the
ssh.key.generateAPI.https://github.com/ParallelSSH/ssh-python/blob/master/examples/keygen.py
afaranha commentedon Apr 25, 2025
Sorry if I wasn't clear when I opened the issue, but that enum if for the key type, not the key format, for example, using the terminal I can do this to generate a RSA key:
or
The key type is the same but the format is different.
https://man.openbsd.org/ssh-keygen.1
Do we have a way how to choose a different key format? On the
generatefunction we can only pass the bits and the key type, not the key format.enkore commentedon Apr 25, 2025
Apologies. No, ssh_pki_export_privkey_file_format isn't wrapped by this library.
Added private key file formats and export to file format function for…
[-]Add key format option[/-][+]Add key formats and export file format function[/+][-]Add key formats and export file format function[/-][+]Implement key formats and export file format function[/+]pkittenis commentedon Oct 5, 2025
See https://github.com/ParallelSSH/ssh-python/blob/master/tests/test_keys.py#L16-L27
Exported file formats:
For the two formats.
Added private key file formats and export to file format function for…