Skip to content

Instantly share code, notes, and snippets.

@jarjuk
Last active September 23, 2015 18:47
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 jarjuk/8ab37d28958e3244a4c6 to your computer and use it in GitHub Desktop.
Save jarjuk/8ab37d28958e3244a4c6 to your computer and use it in GitHub Desktop.
  This gist contains code for blog post [EC2 Keypairs](https://jarjuk.wordpress.com/2015/09/23/ec2-keypairs)
  - example-stack.json : CloudFormration JSON template to create stack using example EC2 key-pair
  - verify-keys.sh: a script to verify Amazon fingerprint with OpenSSH private key fingerprint
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "demo/6 - A simple Amazon EC2 instance created using aws-must tool",
"Parameters": {
"InstanceType": {
"Description": "EC2 reousrce instance type",
"Type": "String",
"Default": "t2.micro"
},
"KeyName": {
"Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance",
"Type": "AWS::EC2::KeyPair::KeyName",
"Default": "example-key"
},
"SSHLocation": {
"Description": "The IP address range that can be used to SSH to the EC2 instances",
"Type": "String",
"Default": "0.0.0.0/0"
}
},
"Mappings": {
"AWSInstanceType2Arch": {
"t2.micro": {
"Arch": "64"
}
},
"AWSRegionArch2AMI": {
"ap-northeast-1": {
"64": "ami-90815290"
},
"ap-southeast-1": {
"64": "ami-0accf458"
},
"ap-southeast-2": {
"64": "ami-1dc8b127"
},
"cn-north-1": {
"64": "ami-eae27fd3"
},
"eu-central-1": {
"64": "ami-3248712f"
},
"eu-west-1": {
"64": "ami-d74437a0"
},
"sa-east-1": {
"64": "ami-0f6ced12"
},
"us-east-1": {
"64": "ami-83c525e8"
},
"us-west-1": {
"64": "ami-61b25925"
},
"us-gov-west-1": {
"64": "ami-51513172"
},
"us-west-2": {
"64": "ami-57e8d767"
}
}
},
"Resources": {
"MyDefaultSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Enable SSH access via port 22",
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "22",
"ToPort": "22",
"CidrIp": {
"Ref": "SSHLocation"
}
}
]
}
},
"MyEC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"KeyName": { "Ref": "KeyName" },
"ImageId": { "Fn::FindInMap": [ "AWSRegionArch2AMI", { "Ref": "AWS::Region" },
{ "Fn::FindInMap": [ "AWSInstanceType2Arch", "t2.micro", "Arch" ] } ]
},
"InstanceType": "t2.micro",
"SecurityGroups": [ { "Ref": "MyDefaultSecurityGroup" } ]
}
}
},
"Outputs": {
"Exampleinstance": {
"Description": "Public IP address of the newly created EC2 instance",
"Value": { "Fn::GetAtt": [ "MyEC2Instance", "PublicIp" ] }
}
}
}
#!/bin/bash
FINGER_PRINT_PUB=$( aws ec2 describe-key-pairs --query 'KeyPairs[?KeyName==`example-key`].KeyFingerprint' --output text)
#echo ${FINGER_PRINT_PUB}
FINGER_PRINT_PRIV=$( openssl pkey -in example-key -pubout -outform DER | openssl md5 -c | cut -d' ' -f2)
#echo ${FINGER_PRINT_PRIV}
if [ "$FINGER_PRINT_PRIV" == "$FINGER_PRINT_PUB" ]; then
echo match
else
echo WARNING no match
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment