Checking ssh public key fingerprints (2024)

Index

  • Overview
  • Checking by eye
  • Displaying fingerprints in other formats
  • Put the key in DNS
  • References
  • Technical Bits

What is this all about ?

Summary: increasing security by verifying the identity of the machine that you connect to with ssh by eye and with SSHFP in DNS.

ssh allows you to connect to a remote machine with the data between the two machines being encrypted. You can then securely do: command line login, file copy, tunnel other protocols (eg: rsync, X11), ... You authenticate by either typing a password or key exchange.

A big vulnerability is a man in the middle attack where some malevolent snooping entity (Mallory) between you and the remote machine intercepts all traffic, decrypts it & reencrypts before sending it on. Mallory can do this fast enough so that you are not aware of his existance.

To protect you against this your ssh program checks the remote ssh server's fingerprint with the fingerprint saved from the last time it connected. If the fingerprint has changed you will be warned and asked if you wish to continue. In openssh (the ssh used on most Linux systems) this fingerprint is stored in $HOME/.ssh/known_hosts.

The fingerprint is a short version of the server's public key; it is easier for you to verify than the full key. It is very hard to spoof another public key with the same fingerprint.

The problem

When you connect to a machine for the first time you do not have the fingerprint in your known_hosts, so ssh has nothing to compare it to, so it asks you. This page describes ways in which you can do more than blindly say yes.

Checking a ssh server key fingerprint by eye

When you connect to a machine for the first time you will be told that the authenticity can't be established and presented with a key fingerprint to check. Something like this:

The authenticity of host 'mint.phcomp.co.uk (78.32.209.33)' can't be established.RSA key fingerprint is 6a:de:e0:af:56:f8:0c:04:11:5b:ef:4d:49:ad:09:23.Are you sure you want to continue connecting (yes/no)? no

You might find that the fingerprint is shown in a different format — just keep reading.

To be able to check the fingerprint you need to know what it is. You will probably find the .pub files in /etc/ssh/ that contain . This will generate the fingerprints that you can check:

cd /etc/sshfor file in *sa_key.pubdo ssh-keygen -lf $filedone

There is little point in doing this after you have logged in, a sufficiently ingenious Mallory could modify what the above generates on the fly so that you see what he wants you to see. This needs to be done before hand and you can then check it with what you see. You might print the fingerprints out and keep them in your briefcase or wallet.

Displaying fingerprints in other formats

You might find that the fingerprint is generated in a different format from what you have. This section tells you how, when connecting, you get the ssh client to show them in different formats and, on the server, have ssh-keygen generate different format references.

You may need to mix and match depending on what you have in front of you and where you are able to run commands.

Forcing MD5 hash in hexadecimal

This is the format shown above. You can force ssh to display this thus:

 $ ssh -o FingerprintHash=md5 host.example.org

SHA256 in base64

This new format looks as below:

The authenticity of host 'mint.phcomp.co.uk (78.32.209.33)' can't be established.RSA key fingerprint is SHA256:jP0pfKJ9OAXt2F+LM7j3+BMalQ/2Koihl5eH/kli6A4.Are you sure you want to continue connecting (yes/no)? 

You can request this with:

 $ ssh -o FingerprintHash=sha256 host.example.org

You can get ssh-keygen to display it:

 ssh-keygen -l -E sha256 -f $file


This is used in OpenSSH 6.8 & later. The FingerprintHash is not available in old versions.

ASCII Art Visual Host Key

This displays the host key in a box and is, hopefully, easier to recognise than a string of numbers. It can be used to display both MD5 and SHA256 keys. It looks like this:

The authenticity of host 'mint.phcomp.co.uk (78.32.209.33)' can't be established.RSA key fingerprint is SHA256:jP0pfKJ9OAXt2F+LM7j3+BMalQ/2Koihl5eH/kli6A4.+---[RSA 2048]----+| || || . . || +. . = || . S= o + || .oo+.. o o|| E.=***.= + || .=*=BoXo+ || .o+=o=+*o. |+----[SHA256]-----+Are you sure you want to continue connecting (yes/no)? 

You can request ssh to display it thus:

 $ ssh -o VisualHostKey=yes host.example.org

You can request MD5 or SHA256 keys, eg:

 $ ssh -o VisualHostKey=yes -o FingerprintHash=sha256 host.example.org

On the server ssh-keygen will display when given the -v option. Combine this with -E md5 or -E sha256 for the fingerprint hash algorithm:

 ssh-keygen -lv -E sha256 -f $file

Checking of a ssh server key via DNS

You can put the server keys fingerprint in DNS (Domain Name System) and get ssh to tell you if what it the two fingerprints match. This is not a guarantee but it makes Mallory's job harder since he needs to spoof DNS as well as ssh, which can be done as few domains yet implement DNSSEC.

Configuring DNS

  • Generate the SSHFP fingerprint information to go into DNS:

    cd /etc/sshfor file in *sa_key.pubdo ssh-keygen -r freshmint.phcomp.co.uk -f $file -gdonefreshmint.phcomp.co.uk IN TYPE44 \# 22 02 01 e8fe15b374207a2e6ee99bbbadc87ecd068c17f8freshmint.phcomp.co.uk IN TYPE44 \# 22 01 01 e5091496bda76d015e89db0bf925ffb1b9d8facb

    The above output should be used for bind versions earlier than 9.5.0a1, after that the SSHFP RR type is understood:

    freshmint.phcomp.co.uk IN SSHFP 02 01 e8fe15b374207a2e6ee99bbbadc87ecd068c17f8freshmint.phcomp.co.uk IN SSHFP 01 01 e5091496bda76d015e89db0bf925ffb1b9d8facb
  • Enter the above 2 RR (resource records) into the DNS for the machine. The complete record for the machine looks like:

    freshmint IN A 78.32.209.33 IN AAAA 2001:4d48:ad51:2f00::2:2 IN MX 10 freshmint IN SSHFP 1 1 b4b8f2f051a16f57f69590c7c06aeaad039a3882 IN SSHFP 2 1 ea35c2064a5fc2ec9f51da2e7c790966f9844e59mint IN CNAME freshmint
  • Check that this DNS update is correct with host -a your.machine.name. You should see the SSHFP lines as above, although with old versions of host it may not display properly but like:

    freshmint.phcomp.co.uk.259200 IN TYPE44 \# 22 0101b4b8f2f051a16f57f69590c7c06aeaad039a3882freshmint.phcomp.co.uk.259200 IN TYPE44 \# 22 0201ea35c2064a5fc2ec9f51da2e7c790966f9844e59

Using the DNS SSHFP RR

  • Configure your local ssh client, do this for just you be editing $HOME/.ssh/config or system wide /etc/ssh/ssh_config (on Minix: /usr/pkg/etc/ssh/ssh_config):

    VerifyHostKeyDNS ask

    You can also specify this on the command line when connecting. Note how you are told how the DNS fingerprint matches:

    ssh -o VerifyHostKeyDNS=ask freshmint.phcomp.co.ukThe authenticity of host 'freshmint.phcomp.co.uk (2001:4d48:ad51:2f00::2:2)' can't be established.RSA key fingerprint is 6a:de:e0:af:56:f8:0c:04:11:5b:ef:4d:49:ad:09:23.Matching host key fingerprint found in DNS.Are you sure you want to continue connecting (yes/no)?
  • If the fingerprint in the DNS does not match you will see the following — you may have seen similar before, but this is on a first connection:

    ssh -o VerifyHostKeyDNS=ask freshmint.phcomp.co.uk@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!Someone could be eavesdropping on you right now (man-in-the-middle attack)!It is also possible that the RSA host key has just been changed.The fingerprint for the RSA key sent by the remote host is6a:de:e0:af:56:f8:0c:04:11:5b:ef:4d:49:ad:09:23.Please contact your system administrator.Update the SSHFP RR in DNS with the new host key to get rid of this message.The authenticity of host 'freshmint.phcomp.co.uk (2001:4d48:ad51:2f00::2:2)' can't be established.RSA key fingerprint is 6a:de:e0:af:56:f8:0c:04:11:5b:ef:4d:49:ad:09:23.No matching host key fingerprint found in DNS.Are you sure you want to continue connecting (yes/no)? 

Other things of interest

  • Passwordless login with SSH

References

Technical bits

You don't really need to understand this bit to use the above; however if you are a technical nerd you will want to know.

Thanks

Thanks to Katie Foster <Katie.Foster@auspost.com.au> for reporting an error in a previous version of this page.

License and copyright

All description & sample files copyright (c) 2012, 2016 Parliament Hill Computers. Author: Alain D D Williams.

You may used these files as the basis your own (or organisation's/company's) project(s) (under whatever licence that you see fit). You may not claim ownership or copyright of any substantially unmodified files. Acknowledgement would be appreciated, but is not necessary.

These demonstrations are made available in the hope that they are useful. There may be errors: there is no warranty at all, use at your own risk.

Return to tutorial home.

If you want any help using the above, or have any comments or suggestions, please contact us.

Checking ssh public key fingerprints (2024)

FAQs

How to check SSH public key fingerprint? ›

Display the SSH key fingerprint of the remote device by entering the following command syntax:
  1. ssh-kengen -l -f <path/to/SSH public key file>
  2. For example, ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub.
  3. Note: The above example assumes that the SSH server uses ECDSA public key in the /etc/ssh directory.
Apr 13, 2023

How to validate SSH public key? ›

Procedure
  1. Log in the server as 'root' using SSH, or use the WHM: Terminal feature.
  2. Change into the /root/. ssh/ directory on the server. ...
  3. Use the command 'ls -al' to list all files in the directory, and locate your private/public keypair you wish to check. ...
  4. Use the following command, to test both files. ...
  5. That's it.
Oct 31, 2021

How do I view the public key of SSH? ›

How to view your SSH public key on Linux
  1. Using the ssh-agent command.
  2. Run the following command. ssh-agent sh -c 'ssh-add; ssh-add -L'
  3. After successful authentication, your SSH public key will be displayed in the terminal.
  4. Copy and paste it where you need it.
Sep 12, 2023

What is the fingerprint of SSH host key? ›

In openssh (the ssh used on most Linux systems) this fingerprint is stored in $HOME/. ssh/known_hosts . The fingerprint is a short version of the server's public key; it is easier for you to verify than the full key. It is very hard to spoof another public key with the same fingerprint.

Is key fingerprint same as public key? ›

In public-key cryptography, a public key fingerprint is a short sequence of bytes used to authenticate or look up a longer public key. Fingerprints are created by applying a cryptographic hash function to a public key.

What is the format of SSH public key fingerprint? ›

MD5 and SHA256 are supported as formats for the fingerprints. Currently SHA256 is being used more and more, but MD5 fingerprints can still be found in some cases. For this reason, the fingerprints should be determined in both formats. In most cases, multiple keys are generated for an SSH server.

How to verify a public key? ›

Verify Digital Signature with RSA Public Key using message/text
  1. Get an instance of a Signature object, and pass SHA256withRSA algorithm as an argument.
  2. Obtain an instance of the key you want to use for the Sign Verify operation using the getPublicKey method of the NAEKey class.

How to check if ssh key has password? ›

The easiest way in this case is to run some operation on them using ssh-keygen . If it will ask for a passphrase, it has one (or it is not a ssh key), if not it does not have a passphrase: $ ssh-keygen -yf rsa_enc Enter passphrase: $ ssh-keygen -yf rsa ssh-rsa AAAAB3NzaC1y...

How to check ssh-agent keys? ›

Running ssh-add -l will display all keys currently known to your agent. If the list is empty, you have an ssh-agent running, but no keys currently unlocked.

What is the SSH public key? ›

What is an SSH key? updated on: 01.22.2024. An SSH key is a secure access credential used in the Secure Shell (SSH) protocol. SSH key pairs use public key infrastructure (PKI) technology, the gold standard for digital identity authentication and encryption, to provide a secure and scalable method of authentication.

How to open SSH public key format? ›

Convert to OpenSSH format on Microsoft Windows
  1. Save the public key as a . ...
  2. Open Command Prompt and enter: cd file location .
  3. Replace file location and select enter to go to the folder where your key file is saved.
  4. Copy and paste this command into Command Prompt: ssh-keygen -i -f filename.pub > new-filename.pub.
May 24, 2024

How do I check my SSH fingerprints? ›

To verify your fingerprint, log in to your VPS server through a trusted method (for example, the console in your BitLaunch control panel) and run the ssh-keygen command to get a readout of your key fingerprint: ED25519: SHA256: ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key. pub.

How to get fingerprint of public key? ›

5.4 Display the Fingerprint of the Host Public Key
  1. Log in to the server.
  2. Use ssh-keygen to display the host key fingerprint: Copy ssh-keygen -F /etc/ssh2/hostkey.pub.

What can cause a SSH fingerprint to change? ›

Another common reason this error triggers is when the IP address of the server you are SSHing to has changed. The known_hosts file essentially encodes IP,SSH Host Key Fingerprint,host name. If the IP or SSH Key Fingerprint change for a hostname, you will get a warning.

How do I find the fingerprint of a PGP public key? ›

To check the fingerprint of a key:

Select the PGP key from the list. Right click the key and select Properties. In the new dialog, select the Details tab. You can see the fingerprint of the key on the left hand side.

How to get ssh host key fingerprint windows? ›

For Windows 10 & 11
  1. Press the Windows key or open up the Start Menu. Type “cmd”.
  2. Under “Best Match”, click “Command Prompt”.
  3. In the command prompt, use the ssh-keygen command: ...
  4. The system will now generate the key pair and display the key fingerprint and a randomart image. ...
  5. Open your file explorer.

How can you verify the fingerprint of a target server's ssh host key? ›

The command ssh-keyscan could gather the public host keys for the target server and the command ssh-keygen -l could show the fingerprint of the specified public key file.

Top Articles
Understanding Architect Credentials
Sample Letter to Credit Bureaus Disputing Errors on Credit Reports
Dunhams Treestands
The UPS Store | Ship & Print Here > 400 West Broadway
Frank Lloyd Wright, born 150 years ago, still fascinates
Amtrust Bank Cd Rates
Devotion Showtimes Near Mjr Universal Grand Cinema 16
David Packouz Girlfriend
Umn Pay Calendar
Signs Of a Troubled TIPM
1Win - инновационное онлайн-казино и букмекерская контора
Persona 4 Golden Taotie Fusion Calculator
United Dual Complete Providers
Vcuapi
Colts Snap Counts
Houses and Apartments For Rent in Maastricht
Michael Shaara Books In Order - Books In Order
Foxy Brown 2025
Crawlers List Chicago
Sussyclassroom
Best Transmission Service Margate
A Person That Creates Movie Basis Figgerits
Filthy Rich Boys (Rich Boys Of Burberry Prep #1) - C.M. Stunich [PDF] | Online Book Share
Ceramic tiles vs vitrified tiles: Which one should you choose? - Building And Interiors
Jeff Nippard Push Pull Program Pdf
Naya Padkar Gujarati News Paper
Impact-Messung für bessere Ergebnisse « impact investing magazin
2023 Ford Bronco Raptor for sale - Dallas, TX - craigslist
897 W Valley Blvd
Meowiarty Puzzle
Craftsman Yt3000 Oil Capacity
Craigslist Sf Garage Sales
Advance Auto Parts Stock Price | AAP Stock Quote, News, and History | Markets Insider
Gr86 Forums
Garrison Blacksmith's Bench
Final Exam Schedule Liberty University
Aliciabibs
Why Gas Prices Are So High (Published 2022)
Scanning the Airwaves
Mandy Rose - WWE News, Rumors, & Updates
The disadvantages of patient portals
Body Surface Area (BSA) Calculator
Discover Things To Do In Lubbock
What Is The Optavia Diet—And How Does It Work?
Europa Universalis 4: Army Composition Guide
Sky Dental Cartersville
Upcoming Live Online Auctions - Online Hunting Auctions
St Als Elm Clinic
Varsity Competition Results 2022
Latest Posts
Article information

Author: Lilliana Bartoletti

Last Updated:

Views: 6229

Rating: 4.2 / 5 (53 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Lilliana Bartoletti

Birthday: 1999-11-18

Address: 58866 Tricia Spurs, North Melvinberg, HI 91346-3774

Phone: +50616620367928

Job: Real-Estate Liaison

Hobby: Graffiti, Astronomy, Handball, Magic, Origami, Fashion, Foreign language learning

Introduction: My name is Lilliana Bartoletti, I am a adventurous, pleasant, shiny, beautiful, handsome, zealous, tasty person who loves writing and wants to share my knowledge and understanding with you.