Snowcrash
Snowcrash

Reputation: 86087

SSH key pair - add to EC2 instance

When you create a Key Pair in the AWS console, then create an EC2 instance is that key automatically added to that instance?

Or do you have to add it when creating the EC2 instance?

Upvotes: 1

Views: 709

Answers (1)

franklinsijo
franklinsijo

Reputation: 18270

While launching an EC2 instance from AWS Console, you will be prompted to choose a Key Pair. The Public Key of this chosen Key Pair will be added to the authorized_keys file of the default login user.

If launching an EC2 instance using
AWS CLI:

aws ec2 run-instances --image-id ami-id --key-name name_of_keypair --other-options

Python Boto3:

ec2client = boto3.client('ec2')
ec2client.run_instances(ImageId='ami-id',
                        KeyName='name_of_keypair',
                        ....)

Upvotes: 3

Related Questions