An OpenSSH public key file, such as id_ed25519.pub, is one line of text.
The same line, with optional options in front, is a line of
authorized_keys. The key itself is in the SSH wire encoding of RFC 4253,
base64-encoded (OpenSSH PROTOCOL, section 5.1). Sources: RFC 4251 section
5 (data types), RFC 4253 section 6.6, RFC 5656 section 3.1, RFC 8709 section 4, RFC 4716
section 3, OpenSSH’s sshd(8), ssh-keygen(1),
PROTOCOL, PROTOCOL.key and PROTOCOL.u2f, the
OpenSSH source files named below, the OpenSSH release notes, and
draft-miller-ssh-cert for certificates.
The key line
[options] key-type base64-key [comment]
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI… alice@laptop
| Field | Meaning |
|---|---|
| Options | Only in authorized_keys: comma-separated, no spaces except inside double quotes (sshd(8)). See options. |
| Key type | The algorithm name, which must match the type inside the encoded key, or OpenSSH rejects the line with a key type mismatch (sshkey_read in sshkey.c). See key types. |
| Key | Base64 of the key in wire encoding. |
| Comment | Free text after the key, not used for anything by sshd; ssh-keygen initialises it to user@host (ssh-keygen(1)). |
In authorized_keys, empty lines and lines starting # are
ignored, and lines may be up to 8 kilobytes long (sshd(8), “AUTHORIZED_KEYS
FILE FORMAT”).
Wire encoding
Values are a series of (RFC 4251 section 5):
- uint32: 4 bytes, big-endian.
- string: a uint32 length, then that many bytes, with no terminating null.
- mpint: a string holding a two’s complement big-endian number,
with no unneeded leading
00orFFbytes; a positive number whose top bit is set gets a leading00, and zero is an empty string.
Every key starts with its type as a string, which is why every Ed25519 key’s base64
starts AAAAC3NzaC1lZDI1NTE5: 00 00 00 0B and
ssh-ed25519.
Key types
| Key type | Encoding after the type string | Defined in |
|---|---|---|
ssh-rsa | mpint e (public exponent), mpint n (modulus) | RFC 4253 section 6.6 |
ssh-dss | mpint p, q, g, y. OpenSSH removed DSA support in OpenSSH 10.0 (release notes). | RFC 4253 section 6.6 |
ecdsa-sha2-nistp256, -nistp384, -nistp521 | string curve identifier (nistp256…, section 6.1), string Q (the public point encoded as in SEC1 section 2.3.3; point compression may be used) | RFC 5656 section 3.1 |
ssh-ed25519 | string of the 32-byte public key | RFC 8709 section 4 |
ssh-ed448 | string of the 57-byte public key. Not among OpenSSH’s key types (enum sshkey_types in sshkey.h). | RFC 8709 section 4 |
sk-ecdsa-sha2-nistp256@openssh.com | string curve name, ec_point Q, then string application (“user-specified, but typically ssh:”): a FIDO security key | OpenSSH PROTOCOL.u2f |
sk-ssh-ed25519@openssh.com | string public key, then string application | OpenSSH PROTOCOL.u2f |
ssh-mldsa44-ed25519 | A hybrid post-quantum key combining ML-DSA-44 and Ed25519: one string of 1,344 bytes, the 1,312-byte ML-DSA-44 public key followed by the 32-byte Ed25519 public key (ssh-mldsa-eddsa.c and crypto_api.h in OpenSSH). Experimental with an @openssh.com suffix in OpenSSH 10.4, enabled under this name in OpenSSH 10.6 (release notes). | draft-miller-sshm-mldsa44-ed25519-composite-sigs |
…-cert-v01@openssh.com | An OpenSSH certificate: the key type, a nonce, the key’s own fields, then serial number, certificate role, identifier, principals, valid after, valid before, critical options, extensions, reserved, the signing CA key and the signature | draft-miller-ssh-cert section 2.1, which OpenSSH’s PROTOCOL (section 1.3) refers to |
Certificates
From draft-miller-ssh-cert-06 (November 2025, section 2), which describes what
OpenSSH’s PROTOCOL.certkeys (no longer available at the address the
audit tried) defined. The draft’s key type names have no -v01@openssh.com
suffix; it says each is equivalent to the OpenSSH vendor name with that suffix, for
example ssh-ed25519-cert-v01@openssh.com. All values use the wire types
above, plus uint64 (8 bytes, big-endian) and byte[] (bytes
whose length is fixed by context).
string key type e.g. "ssh-ed25519-cert"
string nonce random, at least 16 bytes, 32 typical
byte[] public key fields as in the table below
uint64 serial number
uint32 certificate role 1 = SSH2_CERT_TYPE_USER, 2 = SSH2_CERT_TYPE_HOST
string identifier UTF-8, for display and logs
string principals zero or more strings, each a UTF-8 name
uint64 valid after seconds since 1970-01-01 UTC; 0 = valid from any time
uint64 valid before same; 0xFFFFFFFFFFFFFFFF = no expiry
string critical options key/value pairs (below)
string extensions key/value pairs (below)
string reserved ignored if not empty
string signature key the CA’s public key blob; a certificate must not be used as a CA key
string signature over everything from "key type" to "signature key"
| Certificate type | Certifies | Public key fields |
|---|---|---|
ssh-rsa-cert | RSA | mpint e, mpint n |
ssh-dss-cert | DSA | mpint p, q, g, y |
ecdsa-sha2-nistp256-cert, …nistp384-cert, …nistp521-cert | ECDSA | string curve name, string Q |
ssh-ed25519-cert, ssh-ed448-cert | EdDSA | string ENC(A), the public key |
rsa-sha2-256-cert, rsa-sha2-512-cert | RSA | Names for advertising or requesting these signature algorithms only; never the key type in a stored key |
The signature is in the standard SSH signature encoding for the CA key’s type, for example RFC 5656 section 3.1.2 for an ECDSA CA (see signature formats). A reader that gets an option in critical options that it does not know must refuse the certificate; one that gets an unknown extension ignores it.
Options and extensions
Both sections are zero or more pairs of strings, key then value, sorted by key name.
A flag has an empty value; a text value is a string holding a string
(force-command “sftp” is the value bytes 00 00 00 04 73 66 74 70).
Vendors add their own keys with a domain name, as in foo@example.com.
The draft defines none for host certificates.
| Section | Name | Value | Meaning |
|---|---|---|---|
| Critical option | force-command | string | Run this command for any exec or shell session, and use it in place of the name of a subsystem session. |
| Critical option | source-address | string | Comma-separated allow-list of CIDR ranges (192.0.2.0/29) or wildcard addresses (192.0.2.*); connections from elsewhere are refused. |
| Critical option | verify-required | flag | For key types whose signatures assert user verification (such as FIDO keys): require it, and refuse authentication if it is absent. |
| Extension | no-touch-required | flag | Accept signatures that do not assert user presence. |
| Extension | permit-agent-forwarding | flag | Sessions may request agent forwarding. |
| Extension | permit-port-forwarding | flag | Sessions may request TCP forwarding (tcpip-forward, direct-tcpip). |
| Extension | permit-pty | flag | Sessions may request a pseudo-terminal. |
| Extension | permit-user-rc | flag | Sessions may run ~/.ssh/rc. |
| Extension | permit-X11-forwarding | flag | Sessions may request X11 forwarding. |
A certificate lacking a permit- extension must not allow that feature.
For example the extensions section holding only permit-user-rc is
00 00 00 16 (length 22), 00 00 00 0E
permit-user-rc, 00 00 00 00.
A certificate with its private key
As sent to an SSH agent, draft section 2.5: a string key type, a string holding the whole certificate, then the private fields: RSA mpint d, iqmp, p, q; DSA mpint x; ECDSA mpint d; EdDSA one string, the private key k followed by ENC(A).
Security-key (FIDO) keys
From OpenSSH PROTOCOL.u2f. The public key adds an application string to
the plain key; the private key (the key kept in the file) adds three fields:
string "sk-ssh-ed25519@openssh.com" (or "sk-ecdsa-sha2-nistp256@openssh.com",
string public key which has curve name and ec_point Q here)
string application typically "ssh:"
-- private key only:
uint8 flags
string key_handle
string reserved
The certificate forms, sk-ecdsa-sha2-nistp256-cert-v01@openssh.com and
sk-ssh-ed25519-cert-v01@openssh.com, put the application string after the
key fields and then the usual certificate fields (serial, type, key id, principals,
validity, critical options, extensions, reserved, signature key, signature).
Their private form is: string type, string public certificate structure, string
application, uint8 flags, string key_handle, string reserved.
Signature formats
A signature is string signature format identifier, then a blob
(RFC 4253 section 6.6).
| Format identifier | Blob | Source |
|---|---|---|
ssh-ed25519 | string of the 64-byte signature | RFC 8709 section 6 |
ssh-ed448 | string of the 114-byte signature | RFC 8709 section 6 |
ecdsa-sha2-curve | a string holding mpint r, mpint s | RFC 5656 section 3.1.2 |
sk-ssh-ed25519@openssh.com | string signature, byte flags, uint32 counter | PROTOCOL.u2f |
sk-ecdsa-sha2-nistp256@openssh.com | string (mpint r, mpint s), byte flags, uint32 counter | PROTOCOL.u2f |
webauthn-sk-ecdsa-sha2-nistp256@openssh.com | the same, then string origin, string clientData, string extensions | PROTOCOL.u2f |
RFC 4253 section 6.6 also lists the key formats pgp-sign-rsa and
pgp-sign-dss (OpenPGP certificates, optional), which this page does not lay out.
The signature blob of ssh-rsa and ssh-dss is not reproduced
on this page.
authorized_keys options
From sshd(8), “AUTHORIZED_KEYS FILE FORMAT”; option keywords are
case-insensitive.
| Option | Effect |
|---|---|
restrict | Turns on every restriction: no forwarding of ports, agent or X11, no terminal, no ~/.ssh/rc. |
agent-forwarding, port-forwarding, pty, user-rc, X11-forwarding | Turn back on what restrict turned off. |
no-agent-forwarding, no-port-forwarding, no-pty, no-user-rc, no-X11-forwarding | Turn off one feature. |
command="…" | Run this command whatever the client asks for. |
environment="NAME=value" | Set an environment variable (only if the server’s PermitUserEnvironment allows it). |
from="pattern-list" | Accept the key only from matching host names or addresses (CIDR allowed). |
expiry-time="timespec" | Stop accepting the key after this time. |
permitopen="host:port" | Limit local (-L) forwarding to these destinations. |
permitlisten="[host:]port" | Limit remote (-R) forwarding to these listen addresses. |
cert-authority | The key is a CA trusted to sign user certificates. |
principals="…" | With cert-authority: names a certificate must carry. |
tunnel="n" | Force this tun device on the server. |
no-touch-required | Do not require a touch on a FIDO security key. |
verify-required | Require user verification (such as a PIN) on a FIDO key. |
RFC 4716 public key files
Other SSH implementations write public keys in the SECSH format of RFC 4716, and it
is the default export format of ssh-keygen -e
(ssh-keygen(1)):
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "alice@laptop"
AAAAC3NzaC1lZDI1NTE5AAAAI…
---- END SSH2 PUBLIC KEY ----
Header lines are Tag: value before the base64 (RFC 4716 section 3.3);
tags are case-insensitive and at most 64 bytes, values at most 1024 bytes.
Subject (the login name) and Comment are defined, and tags
starting x- are for private use (sections 3.3.1 to 3.3.3); readers must
ignore tags they do not know. Every line is at most 72 bytes, not counting the line
ending (section 3), and a header continues on the next line when it ends with a
backslash. The base64 is the same wire-encoded key (section 3.4).
The matching private key
OpenSSH stores the private key (id_ed25519 without
.pub) as -----BEGIN OPENSSH PRIVATE KEY----- around base64 of
this structure (PROTOCOL.key; details from sshkey.c). It has
been ssh-keygen’s default since OpenSSH 7.8 (PROTOCOL
section 5.2).
| Field | Type | Meaning |
|---|---|---|
| Magic | bytes | openssh-key-v1 and a zero byte (sshkey.c writes sizeof(AUTH_MAGIC) bytes, which includes the C string’s terminator). |
| Cipher name | string | none, or a cipher when protected by a passphrase; aes256-ctr by default (DEFAULT_CIPHERNAME). |
| KDF name | string | none or bcrypt. |
| KDF options | string | Empty for none; for bcrypt a string salt and a uint32 number of rounds. ssh-keygen uses a 16-byte salt and 32 rounds by default (SALT_LEN, DEFAULT_ROUNDS; ssh-keygen -a). |
| Number of keys | uint32 | OpenSSH writes 1 and rejects any other number when reading. |
| Public keys | string each | Each public key in wire encoding. |
| Private section | string | Encrypted (or plain) list: two uint32 check numbers holding the same random value, then for each key its private key fields (encoded as for the SSH agent) and a comment string, then padding bytes 1, 2, 3 … until the length is a multiple of the cipher’s block size. The check numbers match only if decryption worked, that is, if the passphrase was right. |