Skip to content

Instantly share code, notes, and snippets.

@tuxfight3r
Last active March 17, 2021 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxfight3r/3074cae7cbc389888df8038884529b71 to your computer and use it in GitHub Desktop.
Save tuxfight3r/3074cae7cbc389888df8038884529b71 to your computer and use it in GitHub Desktop.
validating EC2 pem / ssh key pairs
## Get private key fingerprint for AWS generated key ( will match the id in AWS Console)
$ openssl pkcs8 -in test_key.pem -inform PEM -outform DER -topk8 -nocrypt | openssl sha1 -c
(stdin)= f6:38:9c:53:9c:64:a8:b3:40:23:9f:6c:ed:0e:3d:bf:bf:16:bb:1c

## Get fingerpint from Openssh public key only md5 / sha1
$ ssh-keygen -f test_key.pub -e -m PKCS8 | openssl pkey -pubin -outform DER | openssl md5 -c
(stdin)= 55:b6:90:db:34:29:da:60:68:c9:08:24:f1:9f:c8:4b

(or)

$ openssl pkey -in test_key.pem -pubout -outform DER|openssl sha1 -c
(stdin)= 45:96:32:86:dd:34:2b:1e:21:0a:0c:86:e4:07:8b:f1:2c:4a:41:23

## Get fingerpint from Openssh pem file md5 /sha1
$ openssl pkey -in test_key.pem -pubout -outform DER|openssl md5 -c
(stdin)= 55:b6:90:db:34:29:da:60:68:c9:08:24:f1:9f:c8:4b

(or)

$ openssl pkey -in test_key.pem -pubout -outform DER|openssl sha1 -c
(stdin)= 45:96:32:86:dd:34:2b:1e:21:0a:0c:86:e4:07:8b:f1:2c:4a:41:23

Reference: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment