Paweł Prażak
Paweł Prażak

Reputation: 3191

Import existing SSH key to AWS EC2 programmatically

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?

Upvotes: 2

Views: 854

Answers (1)

Paweł Prażak
Paweł Prażak

Reputation: 3191

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:

Upvotes: 1

Related Questions