Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:OpenSSH private key

From ReverseEngineering.wiki
Format
On this wiki Facts · Code · Notes · Topics

The openssh-key-v1 container written by ssh-keygen: PEM-like markers around a base64 binary with the magic openssh-key-v1, cipher and kdf names, a public key list and an optionally encrypted private list.

Armor

Text file whose first line is five dashes, BEGIN, the label OPENSSH PRIVATE KEY and five dashes, and whose last line is the same with END (MARK_BEGIN/MARK_END in sshkey.c, each followed by a newline), base64 in between. The decoded body starts with the 15 bytes openssh-key-v1 plus a NUL (AUTH_MAGIC written with sizeof, which includes the terminator).

Layout (PROTOCOL.key)

All strings are SSH wire strings (uint32 length + bytes), integers big-endian.

byte[]  AUTH_MAGIC ("openssh-key-v1\0")
string  ciphername      ("none" or e.g. "aes256-ctr", the default)
string  kdfname         ("none" or "bcrypt")
string  kdfoptions      (for bcrypt: string salt, uint32 rounds, wrapped in a string)
uint32  number of keys N
string  publickey1 ... publickeyN
string  encrypted, padded list of private keys

The private list is: uint32 checkint twice (equal when decryption worked), then per key the private key in ssh-agent encoding plus a string comment, then padding bytes 1,2,3,... up to the cipher block size. Unencrypted keys use cipher none and kdf none with empty options. sshkey.c rejects kdf none with a cipher other than none, and requires a passphrase when kdf is not none.

Reversing use: an embedded unencrypted key can be spotted by the cipher name "none" right after the magic. The first public key string starts with a string such as ssh-ed25519, see Format:OpenSSH public key. Do not publish real keys.

Technique:Recognizing embedded keys and certificates

Code & repositories

  • https://github.com/openssh/openssh-portable @ 26b1363c7cbf5d01c730f45fc0b4abc5686beaf7 · license: BSD-3-Clause (read from LICENCE; GitHub's detector did not classify it)
    OpenSSH portable: PROTOCOL.key documents the openssh-key-v1 private key format; sshkey.c parses and writes it.
    Tested on: source read, not run: source reading only · checked 2026-10-19; last activity 2026-10-18