1

I want to have a fingerprint of my SSH key file which is a private key (PEM file).

I tried following this and that advice:

key=$(ssh-keygen -yf lony.pem) | echo $key | ssh-keygen -lf /dev/stdin <<<"$key"

Resulting int this error:

/dev/stdin is not a public key file.

The key file looks like:

-----BEGIN RSA PRIVATE KEY-----
..
-----END RSA PRIVATE KEY-----

How can I get the fingerprint?

Community
  • 1
  • 1
lony
  • 6,733
  • 11
  • 60
  • 92

2 Answers2

5

There are several problems with this command pipeline:

key=$(ssh-keygen -yf lony.pem) | echo $key | 
ssh-keygen -lf /dev/stdin <<<"$key"

First, it's not clear why you're trying to pipe (|) the stdout of your assignment statement to the echo statement. The first doesn't produce any output, and the second doesn't consume any input. In the third component, you are piping the stdout from the echo command to stdin of the ssh-keygen...where you are also redirecting stdin using the <<< operator.

The easiest way to get the fingerprint from a private key file is just to run:

ssh-keygen -lf /path/to/privatekey.pem

For example, if we generate a private key:

bash-4.3$ ssh-keygen -f testkey -N ''

We can then compare the output of this:

bash-4.3$ ssh-keygen -lf testkey
2048 SHA256:beF471z86giH7cV49TduNVFD949UXzT+jHxgu+99gmM lars@myhost (RSA)

To this:

bash-4.3$ ssh-keygen -yf testkey | ssh-keygen -lf /dev/stdin
2048 SHA256:beF471z86giH7cV49TduNVFD949UXzT+jHxgu+99gmM no comment (RSA)

And see that we get the same fingerprint from both commands.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • Thanks you are right! I just wanted the fingerprint from the public key. Problem is your last command always results in"/dev/stdin is not a public key file." – lony Apr 04 '16 at 12:31
  • Could it be that AWS is using another fingerprinting method? Using your first method is returning another hash as AWS does :( – lony Apr 04 '16 at 12:32
  • 2
    http://serverfault.com/questions/603982/why-does-my-openssh-key-fingerprint-not-match-the-aws-ec2-console-keypair-finger That solved it – lony Apr 04 '16 at 12:56
-1

WITH AWK PIPE (no spaces in "passphrase comment" only)

bash-4.3$ ssh-keygen -lf sshkey | awk -F " " '{print $2" "$3}'

SHA256:beF471z86giH7cV49TduNVFD949UXzT+jHxgu+99gmM user1sshkey