2
votes

The official documentation on Importing Your Own Key Pair to Amazon EC2 is lacking in details on how to programmatically generate and import a key pair.

How to do it best?

1

1 Answers

1
votes

Create the key pair (max 2048 bits):

ssh-keygen -t rsa -b 2048 -C "ec2@aws" -N "" -f ec2_ssh
chmod 400 ec2_ssh*

Import public key to EC2:

aws ec2 --region=eu-west-1 import-key-pair --key-name ec2_ssh --public-key-material "file://ec2_ssh.pub"

The file://... feature is not mentioned for this command, but it is described here.

Sources: