Does a Passphrase-Protected SSH Key Really Leak Its Comment?
The claim goes round that a passphrase-protected SSH private key still hands over its comment (usually you@laptop) to anyone who reads the file. For current OpenSSH key files, that is mostly wrong. But the idea is pointing at something real, just in a different place.
So let's test it, then work out where the username and hostname really do escape.
Look at the file yourself
Make a throwaway key with a passphrase and a distinctive comment, then poke at the private file.
ssh-keygen -t ed25519 -N 'correct horse' -C 'andy@secret-laptop' -f demo
head -1 demo
grep -c secret-laptop demo demo.pub
sed '1d;$d' demo | base64 -d | strings | head
The header says BEGIN OPENSSH PRIVATE KEY. The grep finds the comment in demo.pub but not in demo. The decoded blob shows plain strings such as openssh-key-v1, aes256-ctr, bcrypt and ssh-ed25519, and no hostname.
Why the comment is not in the clear
The newer format is described in OpenSSH's PROTOCOL.key. The outer layer is unencrypted and holds the cipher name, the KDF name and its parameters, the number of keys and the public key blob. Everything after that is one encrypted section.
Inside that encrypted section sit the private key material and the comment. So with a passphrase set, the comment is protected along with the secret.
You can see the effect in ssh-keygen -c, which changes a key's comment. On a passphrase-protected key it has to ask for the passphrase, because it must decrypt and re-encrypt that section.
Quick detour: the old PEM format never stored it
Keys in the older BEGIN RSA PRIVATE KEY format do not carry a comment at all. The comment only ever lived in the .pub file. That is partly why people see the comment "come back": it was never in the private file, it was in the public one.
Hang on, then why does ssh-add -l show a comment for a key? Because the agent is told it when the key is loaded, after decryption (or from the file name for keys without one). Nothing in that is a leak of the encrypted file.
What the private file does leak
The public key is stored in the clear, so the private file is not anonymous. This is the real finding.
- The key type is visible without the passphrase.
- The KDF and its cost (the bcrypt rounds) are visible, so you can tell how hard a passphrase would be to guess.
- The public key is visible, so anyone with the file can compute its fingerprint and match it against
authorized_keysentries, GitHub's published keys or server logs.
That last point is the useful one for someone investigating a stolen backup. ssh-keygen -l -f demo can print a fingerprint from the private file; I would check on your own version, since this depends on the file being in the new format.
Where the comment really does escape
The comment is in every place the public key goes. That is the part to worry about.
- The
.pubfile, which you paste into forms and emails. authorized_keyson every server you add it to, where the comment is just a free text field.- Git hosting and cloud consoles, which often display it.
- Shared configuration management repos that list public keys.
The default comment is user@hostname. That tells every machine and every admin which account and which machine you use. It is not a secret in the cryptographic sense, but it is metadata you did not mean to publish.
Choosing what the comment says
The comment has no effect on authentication. The server never checks it, so you can set it to anything, or nothing.
# at creation
ssh-keygen -t ed25519 -C '' -f ~/.ssh/id_work
# on an existing key (asks for the passphrase for new-format keys)
ssh-keygen -c -C 'work-2026' -f ~/.ssh/id_work
Remember that changing it only updates your copy. Copies already sitting in authorized_keys elsewhere keep the old text until you edit them.
A label such as work-2026 still helps you audit keys later, without naming your machine. That is my preference; an empty comment is equally valid.
A caveat on file names
If you keep keys in files called id_ed25519_andy_secret-laptop, the name leaks regardless of any encryption. File names, directory listings and backup manifests are all outside the key format. Name keys for their purpose, not for you.
And a passphrase does not hide the public key, only the private one. If linking two of your servers by key fingerprint matters to you, use a separate key per service rather than relying on the file being encrypted.