What do SSH keys look like? Public and private keys shown

See what SSH public keys, private keys and fingerprints look like, how to read each part, and how to tell key types and formats apart.

6–9 minutes
Desk with a monitor showing code and small plants

A public SSHSSH A secure way to type commands on a server from your own computer, as if you were sitting at it. More about SSH → key is a single line of text that starts with the key type, such as ssh-ed25519, while a private key is a block of text between -----BEGIN and -----END lines. This guide is for anyone who has opened an SSH key file, or been asked to paste one somewhere, and wants to know what they are looking at and whether it is the right file.

A public key is one line in three parts: the key type (for example ssh-ed25519 or ssh-rsa), a long run of Base64 text starting with AAAA, and an optional comment such as you@laptop. A private key is several lines wrapped in **-----BEGIN OPENSSH PRIVATE KEY----- and -----END OPENSSH PRIVATE KEY-----**. Only the one-line public key (the .pub file) is ever shared.

What a public SSH key looks like

Your public key is in the file ending in .pub, usually ~/.ssh/id_ed25519.pub (see where SSH keys are stored if yours is elsewhere). Show it with:

cat ~/.ssh/id_ed25519.pub

You will see one line like this (shortened here):

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGx7k2...q9Vf exampleco@laptop

It has three parts separated by single spaces:

  1. Key type. ssh-ed25519 here. It tells the server which algorithm to use when checking your signature.
  2. Key data. The long string starting AAAA is the actual public key, written in Base64 (a way of turning binary data into plain letters, numbers, + and /). It can end with one or two = signs.
  3. Comment. Free text, usually username@hostname from the computer that made the key. SSH ignores it; it is only there so humans can tell keys apart. You can set it when creating the key with ssh-keygen -C "your label".

The whole thing must stay on one line. If a terminal, email or chat tool wraps it onto several lines and you paste it like that, the server will not recognise it.

How to recognise each key type

The first few characters of the key data repeat the key type in encoded form, so you can identify a key even if the first word is missing.

Key type labelKey data starts withTypical length of the line
ssh-ed25519AAAAC3NzaC1lZDI1NTE5Short: 68 characters of key data
ssh-rsaAAAAB3NzaC1yc2ELong: several hundred characters
ecdsa-sha2-nistp256AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYMedium
sk-ssh-ed25519@openssh.comAAAAGnNrLXNzaC1lZDI1NTE5Short, for hardware security keys

An Ed25519 public key is always the same short length. An RSA key gets longer as the key size grows, so a 4096-bit RSA line is roughly twice the length of a 2048-bit one. If you are choosing a type, the SSH keys explainer covers which one to use.

What a key looks like inside authorized_keys

On a server, the public keys allowed to log in to an account are listed in ~/.ssh/authorized_keys, one per line, in exactly the same format. A line may also begin with options that restrict the key, for example:

from="203.0.113.10",no-port-forwarding ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGx7k2...q9Vf exampleco@laptop

Here the key only works from the address 203.0.113.10. The options come first, then a space, then the normal three-part key.

What a private SSH key looks like

The private key is the file with the same name but no .pub ending, such as ~/.ssh/id_ed25519. Modern versions of OpenSSH write it like this (content replaced with dots):

-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
...
-----END OPENSSH PRIVATE KEY-----

The body is Base64, wrapped at 70 characters per line. Every key in this format starts with b3BlbnNzaC1rZXktdjE, which is the encoded form of the words openssh-key-v1. An Ed25519 private key is only a handful of lines; an RSA private key is much longer.

Never paste the contents of a private key into a website, ticket, chat or email, and never upload it to a server you log in to. Anyone who has the file (and its passphrase, if it has one) can log in as you. If you have shared it by mistake, create a new key pair and remove the old public key from every server.

Is the private key protected by a passphrase?

In the OpenSSH format, the header looks the same whether or not the key has a passphrase. Two ways to tell:

  • Look at the start of the body. A key with no passphrase begins b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQ (the encoded word none appears twice). A protected key created with current OpenSSH defaults begins b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHI, which encodes the cipher name aes256-ctr.
  • Ask ssh-keygen. This command prints the matching public key. If the private key has a passphrase, it asks for it first:
ssh-keygen -y -f ~/.ssh/id_ed25519

Older private key formats you may meet

Keys made by older tools, or converted for other software, look different:

First lineFormatWhere you see it
-----BEGIN OPENSSH PRIVATE KEY-----Current OpenSSH formatKeys made by OpenSSH 7.8 and later
-----BEGIN RSA PRIVATE KEY-----Older PEM format for RSAOld keys, some cloud consoles and libraries
-----BEGIN EC PRIVATE KEY-----Older PEM format for ECDSAOld ECDSA keys
-----BEGIN PRIVATE KEY-----PKCS#8, a general formatKeys exported from other software
PuTTY-User-Key-File-3: ssh-ed25519PuTTY .ppk filePuTTY and tools built on it, mainly Windows

An old PEM key with a passphrase has two extra lines under the header: Proc-Type: 4,ENCRYPTED and DEK-Info:. A PuTTY file shows the key type on its first line, then lines such as Encryption: none or Encryption: aes256-cbc, Comment:, Public-Lines: and Private-Lines:. PuTTYgen can convert between .ppk and OpenSSH formats using its Conversions menu.

What an SSH key fingerprint looks like

A fingerprint is a short summary of a public key, used to check that two keys are the same without comparing hundreds of characters. Services such as GitHub list your keys by fingerprint. Show yours with:

ssh-keygen -lf ~/.ssh/id_ed25519.pub

The output looks like this:

256 SHA256:Xh2bq8b4m1kTqF3rYp0Vd9wZcN7sLe5aUo6jRiHgTyE exampleco@laptop (ED25519)

That is the key size in bits (256 for Ed25519, 2048, 3072 or 4096 for RSA), the SHA256 fingerprint, the comment and the type. Some older systems show fingerprints as pairs of hex digits separated by colons, such as MD5:3f:a1:.... To produce that style for comparison, add -E md5:

ssh-keygen -E md5 -lf ~/.ssh/id_ed25519.pub

Servers have their own keys too, and the fingerprint you are asked to accept the first time you connect is the server’s host key fingerprint, not yours. The guide on connecting to a server with SSH explains that prompt.

Other ways a public key can be written

Some systems, especially network equipment and older commercial SSH servers, want the public key in the RFC 4716 format, which spreads it over several lines:

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "256-bit ED25519, converted by exampleco@laptop from OpenSSH"
AAAAC3NzaC1lZDI1NTE5AAAAIGx7k2...q9Vf
---- END SSH2 PUBLIC KEY ----

Note the four dashes and spaces, rather than five dashes. Convert your OpenSSH key to this format, and back again, with:

ssh-keygen -e -f ~/.ssh/id_ed25519.pub
ssh-keygen -i -f key-from-other-system.pub

PuTTYgen also shows a box labelled “Public key for pasting into OpenSSH authorized_keys file”, which is the normal one-line format.

How to check you have the right file

A quick checklist before you paste a key anywhere:

  • The text starts with ssh-ed25519, ssh-rsa or ecdsa-sha2-, not with -----BEGIN.
  • It is on a single line with no breaks.
  • The file name ends in .pub.
  • On Linux or macOS, ls -l ~/.ssh shows your private key as -rw------- (readable only by you), while the .pub file can be readable by others.

Common problems

SymptomCauseFix
Website says “Key is invalid”You pasted the private key, or the line was wrappedPaste the contents of the .pub file as one line
Server still asks for a passwordThe key in authorized_keys was split over lines or has extra spacesPut the key back on one line, or copy it again with ssh-copy-id
Load key: invalid formatSSH was given a .ppk file or a public key as the identity fileConvert the .ppk with PuTTYgen, or point -i at the private key
UNPROTECTED PRIVATE KEY FILE!The private key is readable by other usersRun chmod 600 ~/.ssh/id_ed25519
Two keys look almost the sameThey share a type prefix but differ laterCompare fingerprints with ssh-keygen -lf instead

If you need to put a key on a server or copy it to the clipboard, copying SSH keys walks through each method.

Official documentation

Get the next guide

One email when there is something worth reading: new guides, errors going around, and hosting changes that affect your site.

No tracking pixels, and one click to leave.

Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.