Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to setup SSHFP records in the DNS for my host. I have done some searching but I haven't found any good example.

  • What are SSHFP records?
  • What does SSHFP records look like?
  • How do I create SSHFP records?
share|improve this question

4 Answers 4

What are SSHFP records?

SSHFP RR records are DNS records that contain fingerprints for public keys used for SSH. They're mostly used with DNSSEC enabled domains. When a SSH client connects to a server it checks the corresponding SSHFP record. If the records fingerprint matches the servers, the server is legit and it's safe to connect.

What does SSHFP records look like?

SSHFP records consist of three things:

  1. Algorithm
  2. Fingerprint type
  3. Fingerprint (in hex)

Algorithm

There are three different algorithms defined in SSHFP as of 2012. Each algorithm is represented by an integer. The algorithms are:

  • 1 - RSA
  • 2 - DSA
  • 3 - ECDSA

Fingerprint type

Two fingerprint types are defined in SSHFP as of 2012. Each fingerprint type is represented by an integer. These are:

  • 1 - SHA-1
  • 2 - SHA-256

How do I generate SSHFP records?

You can use ssh-keygen to generate the records using the -r parameter, followed by the hostname (which does not effect the fingerprints so you can specify whatever you like instead)

Example

Using ssh-keygen and CentOS 6:

[root@localhost ~]# ssh-keygen -r my.domain.com

my.domain.com IN SSHFP 1 1 450c7d19d5da9a3a5b7c19992d1fbde15d8dad34

my.domain.com IN SSHFP 2 1 72d30d211ce8c464de2811e534de23b9be9b4dc4

Note

Sometimes ssh-keygen will ask for the location of the public certificate. If it asks, you will have to run ssh-keygen multiple times and every time specify a different certificate to make sure that you generate all necessary SSHFP records. Your public keys are usually located in /etc/ssh.

share|improve this answer

I'm not sure if ssh-keygen works with existing keys. If not you still can easily assemble them in your shell (which I prefer), and without fancy software or remote interfaces.

A records such as mentioned...

my.domain.com IN SSHFP 2 1 72d30d211ce8c464de2811e534de23b9be9b4dc4

...exist of 6 parts:

part 1: hostname
part 2: Usually "IN" for internet
part 3: "SSHFP", the RR name for type 44
part 4: RSA keys   = "1"
        DSA keys   = "2"
        ECDSA keys = "3"
part 5: The algorithm type:
        SHA-1      = "1"
        SHA-256    = "2"
part 6: You can generate, for example:

        $ awk '{print $2}' /etc/ssh/ssh_host_dsa_key.pub | \
            openssl base64 -d -A | openssl sha1

To make use of it, put VerifyHostKeyDNS ask in your SSH client's config, usually ~/.ssh/config.

share|improve this answer
    
For the record, ssh-keygen -r does generate SSHFP records for existing keys despite the fact that the name of the command suggests it's only for GENerating. –  Celada Jul 3 at 1:58

If you use Puppet, facter has built in support for sshfp. Plus if you are using PuppetDB you can easily extract this info for all your hosts.

facter | grep -i sshfp
  sshfp_dsa => SSHFP 2 1 e1a3e639d6dbd48d3964ebfb772d2d11f1065682
  SSHFP 2 2 4f620ce2bc97d91ae5eff42fba621d65b677ab725f275f56b2abd1303c142b73
  sshfp_rsa => SSHFP 1 1 a78351af371faf3f19533c3a4a9e967543d7d2f5
  SSHFP 1 2 795943a6ee8b53c818cfef5781209e25a6eb4bc386813db60d3ff2c1569692fc

Source

share|improve this answer

Older versions of ssh-keygen don't generate all the available keys (eg. no support for ecdsa and sha256). This script does creates all the records for all available keys in /etc/ssh/:

#!/bin/bash
#
# Creates SSHFP Records vor all available keys
#

HOST="$1"

if (($# < 1))
then
  echo "Usage: sshfpgen <hostname>"
  exit 1
fi

for pubkey in /etc/ssh/ssh_host_*_key.pub
do
  case "$(cut -d _ -f3 <<< "$pubkey")"
  in
    rsa)
      echo "$HOST IN SSHFP 1 1 $(cut -f2 -d ' ' "$pubkey" | base64 -d | sha1sum  | cut -f 1 -d ' ')"
      echo "$HOST IN SSHFP 1 2 $(cut -f2 -d ' ' "$pubkey" | base64 -d | sha256sum  | cut -f 1 -d ' ')"
    ;;
    dsa)
      echo "$HOST IN SSHFP 2 1 $(cut -f2 -d ' ' "$pubkey" | base64 -d | sha1sum  | cut -f 1 -d ' ')"
      echo "$HOST IN SSHFP 2 2 $(cut -f2 -d ' ' "$pubkey" | base64 -d | sha256sum  | cut -f 1 -d ' ')"
    ;;
    ecdsa)
      echo "$HOST IN SSHFP 3 1 $(cut -f2 -d ' ' "$pubkey" | base64 -d | sha1sum  | cut -f 1 -d ' ')"
      echo "$HOST IN SSHFP 3 2 $(cut -f2 -d ' ' "$pubkey" | base64 -d | sha256sum  | cut -f 1 -d ' ')"
    ;;
    ed25519)
      echo "$HOST IN SSHFP 4 1 $(cut -f2 -d ' ' "$pubkey" | base64 -d | sha1sum  | cut -f 1 -d ' ')"
      echo "$HOST IN SSHFP 4 2 $(cut -f2 -d ' ' "$pubkey" | base64 -d | sha256sum  | cut -f 1 -d ' ')"
    ;;
  esac
done

https://github.com/mindfuckup/Scripts/blob/master/sshfpgen

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.