Skip to main content

authkeys

PyPI version Python versions Documentation License: MIT

A pluggable OpenSSH AuthorizedKeysCommand provider. It resolves a user's authorized SSH keys from one or more configured sources — local key files, an HTTP endpoint, a GitHub-style .keys endpoint, or LDAP-stored X.509 certificates — with optional TTL caching, user/group aliasing, and a small unattended HTTP key server for hosts that fetch keys centrally.

Built on the duho declarative CLI framework.

Install

pip install authkeys            # core (file source only)
pip install authkeys[http]      # + HTTP source (requests)
pip install authkeys[ldap]      # + LDAP cert source (ldap3, cryptography)
pip install authkeys[all]       # everything

authkeys targets POSIX systems (it reads the system user/group databases via pwd/grp). The package imports on any platform for testing, but resolution requires a POSIX host.

Usage

authkeys resolve alice          # print alice's authorized keys
authkeys alice                  # 'resolve' is the default command
authkeys serve --bind 0.0.0.0 --port 8090

Wire it into sshd_config:

AuthorizedKeysCommand /usr/bin/authkeys resolve %u
AuthorizedKeysCommandUser nobody

Alongside those, authkeys check resolves a user with per-source tracing on stderr (which source produced which key), authkeys cache show|purge|warm inspects and manages the on-disk cache, and authkeys completion bash|zsh|fish prints a shell completion script. resolve and check also take --format authorized_keys|json, where json emits one object per key with type, key, comment, and options for scripting. See the CLI guide for details.

resolve and check exit 0 on success — including when no keys were found, which sshd reads as "no keys" — and 3 on a config or internal error, never a traceback.

Configuration

authkeys reads (in order) /etc/authkeys.conf, /etc/authkeys/authkeys.conf, /etc/ssh/authkeys.conf, or a colon-separated list passed with --config. A per-user ~/.ssh/authkeys.conf may authorize additional users/groups. See examples/authkeys.conf for a fully commented example.

[cache]
backend = authkeys.cache.AuthKeysCacheMemBackend
expire = 3600
expired_on_error = 1

[source:files]
backend = authkeys.sources.authorizedkeys
paths =
    authorized_keys
    authorized_keys2

[source:ldap]
enabled = 1
backend = authkeys.sources.ldap
server = ldaps://ldap.example.com:636
basedn = o=Example,c=US

Sources

Alias (backend =) Reads keys from Extra dep
authkeys.sources.authorizedkeys ~/.ssh/authorized_keys* files —
authkeys.sources.http an HTTP URL ({username} templated) requests
authkeys.sources.github a GitHub (or similar) .keys endpoint requests
authkeys.sources.ldap X.509 certs in an LDAP directory ldap3, cryptography

Each [source:<name>] section supports enabled and cached (both default true) and an optional sanitize callable to rewrite/drop keys.

Caching

  • AuthKeysCacheMemBackend — per-process, in-memory (default).
  • AuthKeysCacheFileBackend — on-disk under path, shared across invocations.

With expired_on_error = 1, a source failure falls back to the last-known (expired) cached keys instead of returning nothing — useful when the SSH login must not be blocked by a transient LDAP/HTTP outage.

User / group aliasing

A per-user ~/.ssh/authkeys.conf may grant other principals' keys:

[authorized]
users =
    alice
    bob
groups =
    admins

HTTP key server (authkeys serve)

For hosts that can't run the command locally, authkeys serve exposes the same resolution over HTTP:

GET /keys?username=alice&apikey=<key>

Bind address, port, path, and API key come from the [serve] config section (or --bind/--port). The API key is compared in constant time; pull it from the environment with api_key = ${env:AUTHKEYS_APIKEY} to keep it off disk. If no API key is configured, authentication is disabled — only bind to a trusted interface in that case.

License

MIT — see LICENSE.

Metadata

Release files for authkeys 0.4.5

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

Source distribution (sdist)

Source distribution for authkeys 0.4.5
File Size Uploaded
authkeys-0.4.5.tar.gz 55.5 kB Details

Built distribution (wheel)

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

Total release size: 92.3 kB

Release files / authkeys-0.4.5.tar.gz

Download URL authkeys-0.4.5.tar.gz
Size 55.5 kB
Tags Source
SHA-256 checksum
How to use checksums
47596569200cd4577a60ec0717de8b6bfc700f280322717c73c45d299f4c910e
BLAKE2b-256 checksum
How to use checksums
2ee9326833bbd76dffacfcb0ca776fc75afe924fe19c31de484f7799450b5189
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 2, 2026.

Transparency log

Release files / authkeys-0.4.5-py3-none-any.whl

Download URL authkeys-0.4.5-py3-none-any.whl
Size 36.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8cbccb5e5e796d605ea1f8ff9957de61f97eeda05934ad309c00a61c4fdff280
BLAKE2b-256 checksum
How to use checksums
81c0ad7cc7c7eab5b5bd539d56a8f79789d81fed0ef31a3a2f56ec18b5ab0d25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.5 This release

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

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