Atharva Kale
Atharva Kale

Reputation: 59

AWS SSH access key generation procedure and putting on EC2

I wonder how does AWS EC2 puts the SSH public key on the instance and provides private key to end user. I mean to know how this process of creating an SSH key and putting it on EC2 instance is automated.

Upvotes: 0

Views: 1434

Answers (2)

John Rotenstein
John Rotenstein

Reputation: 269276

The keypair is passed to the instance via the EC2 Metadata Service.

From Amazon EC2 key pairs and Linux instances - Amazon Elastic Compute Cloud:

The public key that you specified when you launched an instance is also available to you through its instance metadata. To view the public key that you specified when launching the instance, use the following command from your instance:

curl http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key

An 'on first boot' script pre-installed on the AMI uses the above method to retrieve the public key and then inserts into the /home/ec2-user/.ssh/authorized_keys file.

Please note this method is slightly different if using Instance Metadata v2, as specified on the linked page.

Upvotes: 2

Chris Williams
Chris Williams

Reputation: 35156

This process is actually carried out when the instance boots as part of the user data.

Upvotes: 1

Related Questions