https://github.com/valohai/openssh-key
Tools to deal with OpenSSH2 (RFC4716) keys in Python
https://github.com/valohai/openssh-key
cryptography keys openssh pki python ssh
Last synced: 11 months ago
JSON representation
Tools to deal with OpenSSH2 (RFC4716) keys in Python
- Host: GitHub
- URL: https://github.com/valohai/openssh-key
- Owner: valohai
- License: mit
- Created: 2019-02-12T13:23:31.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-03-05T14:02:11.000Z (over 2 years ago)
- Last Synced: 2024-03-06T12:53:58.686Z (over 2 years ago)
- Topics: cryptography, keys, openssh, pki, python, ssh
- Language: Python
- Homepage:
- Size: 110 KB
- Stars: 1
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# openssh_key
Tools to deal with OpenSSH2 (RFC4716) keys in as pure Python 3 as possible.
These key files are the default format generated by `ssh-keygen` since OpenSSH 7.8 (2018-08-24)
and can be recognized from their `-----BEGIN OPENSSH PRIVATE KEY-----` header.
If you need to simply convert one of these files into the "legacy" PEM format, you can do it using
a recent enough `ssh-keygen` – or you can use this library. In case you just want the conversion done,
```bash
ssh-keygen -e -m PEM -p -f my-openssh-format-private-key
```
will transmute `my-openssh-format-private-key` in-place into PEM.
## Limitations
- Encrypted OpenSSH private key files are not yet supported, and raise an error.
- Not all key formats supported by OpenSSH are supported; the widest support is for RSA keys.
## Requirements
- Python 3.7+
## Usage
Install the package into your environment using your favored tools.
If you need to be able to convert key data into PEM, also install `cryptography`
(or install this package with the `convert` extra, which depends on that module).
The basic API is provided via `openssh_key.OpenSSHKeyFile.parse_text()`, like so:
```python
from openssh_key import OpenSSHKeyFile
with open('my-openssh-format-private-key') as infp:
kf = OpenSSHKeyFile.parse_text(infp)
for keypair in kf.decrypt_keypairs():
print(keypair.public_key_string) # as you'd find in `authorized_keys`
```
See the modules themselves and the tests for more.