/flags/ssh-protocol/ssh-keygen-e-md5-fingerprint
ssh-keygen -l -E md5: show an SSH key fingerprint in MD5 or SHA256 format
- tool
- SSH protocol
- command
- ssh-keygen
- flag
- -E md5|sha256
- default
- sha256 (since OpenSSH 6.8; MD5 hex was the format before)
ssh-keygen -l -E md5 -f key.pub prints a key's fingerprint as the MD5 hash in colon-separated hex (MD5:a7:dd:3c:...), the format OpenSSH used before version 6.8 and that some consoles, appliances and older documentation still show. Without -E, ssh-keygen -l prints SHA256: followed by an unpadded base64 hash. Both are hashes of the same public key blob, so you need the same algorithm on both sides to compare them; -E only changes the hash, not the key.
One key, three formats
A fixed Ed25519 public key (public keys are safe to publish), fingerprinted with the default and with -E:
echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA2/7rHdfkuxwSzyGQICq3l4czQ4URYR6n52vmNYBLCz demo@example.org' > demo_key.pub
ssh-keygen -l -f demo_key.pub
ssh-keygen -l -E md5 -f demo_key.pub
ssh-keygen -l -E sha1 -f demo_key.pub
echo "--- known_hosts style line:"
echo "192.0.2.10 $(cut -d' ' -f1-2 demo_key.pub)" > known_hosts.sample
ssh-keygen -l -E md5 -f known_hosts.sampleOutput
256 SHA256:98O68RFBsU8bbLse1/WNbRxg8peekIUpYZkPVAuT7dI demo@example.org (ED25519) 256 MD5:a7:dd:3c:a1:1c:07:72:38:f1:92:db:9c:b3:db:9d:24 demo@example.org (ED25519) 256 SHA1:CVDVv6a3TYz4xYA6iBqHp3rwy88 demo@example.org (ED25519) --- known_hosts style line: 256 MD5:a7:dd:3c:a1:1c:07:72:38:f1:92:db:9c:b3:db:9d:24 192.0.2.10 (ED25519)
Each line shows the key size, the fingerprint, the comment (or the host name for a known_hosts entry) and the key type. -l reads public key files, private key files (it derives the public key), authorized_keys and known_hosts files, one line per key.
Values of -E
| Value | Output format | Typical use |
|---|---|---|
| sha256 (default) | SHA256: + base64 without padding | Current OpenSSH, GitHub, GitLab, most cloud consoles |
| md5 | MD5: + 16 hex bytes separated by colons | Old OpenSSH clients, some network devices, legacy docs |
| sha1 | SHA1: + base64 | Rare; some older tools |
Related options
| Command | What it does |
|---|---|
| ssh-keygen -l -f FILE | Fingerprint of every key in FILE |
| ssh-keygen -lv -f FILE | Adds the ASCII-art randomart image |
| ssh-keygen -l -F HOST -f ~/.ssh/known_hosts | Find a host in known_hosts and fingerprint its key |
| ssh-keyscan HOST | ssh-keygen -lf - | Fingerprint a server key read from standard input |
| ssh -o FingerprintHash=md5 | Use MD5 in the new-host confirmation prompt |
Verifying a server on first connection
When ssh says The authenticity of host ... can't be established it prints the server key's fingerprint in SHA256. Compare it with the fingerprint published by the administrator, for example the output of ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub run on the server. If the published value is MD5, either ask for SHA256 or connect with -o FingerprintHash=md5 so both use the same format. If a known host's key changed legitimately, remove the old entry first; see remove a host from known_hosts.
Pitfalls
- Different key types, different fingerprints. A server has one key per type (Ed25519, ECDSA, RSA). The fingerprint you compare must be for the type ssh negotiated, which the prompt names.
- Private key files.
ssh-keygen -l -f id_ed25519also accepts the private key file, so a missing.pubfile is no obstacle to getting the fingerprint. - MD5 is for comparison only. MD5 is weak as a hash, so prefer SHA256 when you can choose; it is still adequate for matching against a value you already trust.
FAQ
Why does GitHub or my cloud console show a different fingerprint than ssh-keygen?
Usually only the format differs. OpenSSH 6.8 and later print SHA256 in base64 by default, while some consoles and older tools show the MD5 hash as colon-separated hex. Run ssh-keygen -l -E md5 -f key.pub to get the same format.
Is it safe to share a fingerprint?
Yes. A fingerprint is a hash of the public key, which is public anyway. Publishing host key fingerprints is how users verify a server on the first connection.
Can ssh show MD5 fingerprints when it asks to confirm a new host?
Yes, with -o FingerprintHash=md5 or FingerprintHash md5 in ssh_config. The default is sha256, and comparing in that format is preferable whenever the published fingerprint uses it.