Skip to Content
oxcrypto

authorized_keys

Parse OpenSSH authorized_keys files.

Warning

Experimental: built on the pinned pre-release ssh-key 0.7.0-rc.12.

from oxcrypto.ssh.openssh import OPENSSH

with open("authorized_keys", "rb") as f:
    for entry in OPENSSH.OPENSSH.load_authorized_keys(f.read()):
        print(entry.options, entry.algorithm, entry.comment)
        public_key = entry.public_key()

load_authorized_keys returns one AuthorizedKey per key line and skips blank lines and # comments. Each entry has options (the comma-separated options such as no-pty or command="...", as written), algorithm, comment and public_key(), which returns an oxcrypto public key. The options are returned, not enforced. A malformed line raises ValueError.