{"id":4778,"library":"sshpubkeys","title":"SSH Public Key Parser","description":"sshpubkeys is a Python library for parsing SSH public keys. It supports various key types (RSA, DSA, ECDSA, Ed25519) and can handle authorized_keys file formats, including options like 'command=' or 'no-port-forwarding'. The current version is 3.3.1, and it maintains an active, feature-driven release cadence.","status":"active","version":"3.3.1","language":"en","source_language":"en","source_url":"https://github.com/ojarva/python-sshpubkeys","tags":["ssh","public-key","security","parser"],"install":[{"cmd":"pip install sshpubkeys","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Provides underlying cryptographic primitives for key parsing and validation. Replaced `ecdsa` as of v3.2.0.","package":"cryptography"}],"imports":[{"symbol":"SSHKey","correct":"from sshpubkeys import SSHKey"},{"symbol":"InvalidKeyException","correct":"from sshpubkeys import InvalidKeyException"}],"quickstart":{"code":"from sshpubkeys import SSHKey, InvalidKeyException\nimport os\n\n# This is a dummy example key. Replace with a real key or load from a file.\n# For actual use, avoid hardcoding keys directly in code.\n# A real key might look like: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCq2z/t... user@example.com'\nexample_public_key_string = os.environ.get(\n    'SSH_PUBLIC_KEY', \n    'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCw0Y1c/tFk9k/N... dummy_key@example.com'\n)\n\ntry:\n    key = SSHKey(example_public_key_string)\n    print(f\"Key type: {key.key_type}\")\n    print(f\"Key length: {key.length}\")\n    print(f\"Fingerprint (MD5): {key.hash_md5}\")\n    print(f\"Fingerprint (SHA256): {key.hash_sha256}\")\n    print(f\"Comment: {key.comment}\")\n    key.verify_length() # Ensures key length is standard for its type\n    print(\"Key is valid and has standard length.\")\nexcept InvalidKeyException as e:\n    print(f\"Error parsing SSH key: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"Initialize an SSHKey object from a public key string, retrieve its properties, and perform basic validation. Demonstrates handling of `InvalidKeyException`."},"warnings":[{"fix":"Upgrade your Python environment to Python 3.4+ (preferably 3.6+).","message":"Support for Python 2.6 and Python 3.3 was dropped.","severity":"breaking","affected_versions":"v3.0.0 onwards"},{"fix":"Ensure all DSA keys conform to standard lengths (e.g., 1024-bit). If you rely on non-standard lengths, you may need to regenerate or migrate keys.","message":"Handling of DSA keys changed; 'loose mode' no longer accepts non-standard DSA key lengths.","severity":"breaking","affected_versions":"v3.0.0 onwards"},{"fix":"Refactor code to use only the public API of `SSHKey`. Avoid accessing internal, private attributes or methods that may rely on specific underlying cryptographic libraries.","message":"The internal ECDSA implementation dependency shifted from `ecdsa` to `cryptography`. While generally internal, direct interaction with `_key.ecdsa_key` or similar internal objects will break.","severity":"breaking","affected_versions":"v3.2.0 onwards"},{"fix":"If using Python 3.5, ensure you are on `sshpubkeys` version `3.3.1` or later for correct compatibility, or preferably, upgrade to a newer, actively supported Python version.","message":"Python 3.5 support was temporarily broken in versions immediately preceding `3.3.1`, despite earlier support.","severity":"gotcha","affected_versions":"v3.3.0 (specifically a bug introduced and then reverted by v3.3.1)"},{"fix":"Always use the `key_type` property and verify against the correct 'ed25519' string. Ensure your code doesn't implicitly rely on the old typo for string comparisons or type lookups.","message":"A typo `ed25516` was corrected to `ed25519` for the key type. While primarily an internal fix, users relying on string comparisons with the incorrect type might be affected.","severity":"gotcha","affected_versions":"v3.2.0 onwards (fix applied in v3.2.0)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}