Skip to main content

pyssh2age

Convert SSH Ed25519 keys to age keys, e.g. for sops or sops-nix.

A single-file pure-Python port of ssh-to-age that produces the same keys. Python 3.9+, using only the standard library and ssh-keygen to decrypt passphrase-protected keys.

The conversion is the standard Ed25519 → X25519 mapping (explained here): the age secret is sha512(seed)[:32], and the age public key is the Montgomery u-coordinate of the Ed25519 public point, u = (1 + y) / (1 - y).

Install

$ pipx install pyssh2age    # or: uv tool install pyssh2age

This installs the pyssh2age command and ssh-to-age alias. Or copy src/pyssh2age.py anywhere and run it.

Usage

$ cat ~/.ssh/id_ed25519.pub | pyssh2age
age17044m9u...

$ pyssh2age -i ~/.ssh/id_ed25519.pub
age17044m9u...

$ ssh-keyscan host1 host2 | pyssh2age    # or authorized_keys, known_hosts
skipped key: got ssh-rsa key type, but only ed25519 keys are supported
age1hjm3au...
age1v8zjc4...

$ pyssh2age --private-key -i ~/.ssh/id_ed25519 -o key.txt    # see Security below

Decrypting passphrase-protected private keys needs a Unix-like system; everything else also works on Windows.

For a passphrase-protected key you're prompted on the terminal. In scripts, use --stdinpass or SSH_TO_AGE_PASSPHRASE:

$ systemd-ask-password | pyssh2age --private-key --stdinpass -i ~/.ssh/id_ed25519 -o key.txt

The age identity file (-o) is created with mode 0600, atomically replacing any existing file. As in the Go version, options work with one or two dashes.

Library

import pyssh2age

pyssh2age.ssh_public_key_to_age("ssh-ed25519 AAAA... me@host")    # "age1..."
pyssh2age.ssh_public_keys_to_age(open("authorized_keys").read())  # ["age1...", ...]

key = open("id_ed25519").read()
try:
    identity = pyssh2age.ssh_private_key_to_age(key)              # "AGE-SECRET-KEY-1..."
except pyssh2age.PassphraseRequired:
    identity = pyssh2age.ssh_private_key_to_age(key, passphrase="...")

Failures raise ConvertError; non-Ed25519 keys raise its subclass UnsupportedKeyType. Lower-level helpers: ed25519_public_to_x25519, ed25519_seed_to_x25519, x25519_public, age_recipient, age_identity.

Security

  • The age key is as powerful as the SSH key. The original id_ed25519 file you derived it from can't be recovered, but it is the Ed25519 signing scalar: whoever has it can sign as the SSH key and log in wherever that key is authorized.
  • Output file is written unencrypted (as in the Go version), even if the SSH key has a passphrase. Encrypt it with: pyssh2age --private-key ... | age -p -o key.txt.age.

Development

The tests need ssh-keygen and openssl, and also check results with age if it's installed:

$ python3 tests/test_pyssh2age.py
$ GO_SSH_TO_AGE=/path/to/ssh-to-age python3 tests/test_pyssh2age.py    # also compare with the Go version

License

MIT. Based on ssh-to-age by Jörg Thalheim.

Metadata

Release files for pyssh2age 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyssh2age 1.0.0
File Size Uploaded Provenance Actions
pyssh2age-1.0.0.tar.gz 31.3 kB With provenance Details for pyssh2age-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyssh2age 1.0.0
File Interpreter ABI Platform Actions
pyssh2age-1.0.0-py3-none-any.whl Python 3 none any Details for pyssh2age-1.0.0-py3-none-any.whl

Total release size: 47.0 kB

Release files / pyssh2age-1.0.0.tar.gz

Download URL pyssh2age-1.0.0.tar.gz
Size 31.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4af26dec78f410abced703150e8951589ae826cd05d0f21fd996ee779684924a
BLAKE2b-256 checksum
How to use checksums
b078157f16b11fe54cf96352ef1c3e1dc2bdb67a4d1dad628199b58ed5519947
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / pyssh2age-1.0.0-py3-none-any.whl

Download URL pyssh2age-1.0.0-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00b8ffb3d86e1b4af87f5319b377561a4da0f06add0c9304fbb3f25b5de1ac98
BLAKE2b-256 checksum
How to use checksums
7469b80b7a9b1232776ffb2c777258ee42c8cb0c2218ccf329505fa8cd9acec3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for pyssh2age 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyssh2age-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page