Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use an existing key pair when creating a new EC2 instance?

We know that a key pair must exist in order to access an EC2 instance.

I have created a key pair when I created EC2, but I saw the phrase that I could use an existing key pair.

Does this mean that if you are using an existing key pair, you can access multiple instances with one key pair?

like image 914
COLEAN Avatar asked Oct 19 '25 23:10

COLEAN


2 Answers

Firstly, please note that keypairs are an industry standard for accessing Linux systems. Amazon EC2 supports their use, but the concept of keypairs was not created by AWS. Therefore, any method of using keypairs with Linux systems in general will also apply to Amazon EC2 Linux instances.

When you ssh into a Linux instance, you supply a username and the private half of a keypair. The Linux system will look in the nominated user's .ssh/authorized_keypairs file and will attempt to find the matching public half of the keypair. If found, it will allow you to start the ssh session.

Therefore, any keypair can be added to a user's .ssh/authorized_keys file. It can include multiple keypairs, all of which would be permitted to login as that user.

As a convenience, Amazon EC2 allows you to create or upload keypairs to AWS. They will appear in the Key Pairs section of the console. Then, when launching a new Amazon EC2 instance, you can nominate one of those keypairs. Software installed on the EC2 instance will copy the public half of the keypair to the /home/ec2-user/.ssh/authorized_keys file.

Bottom line: You can use the same keypair on multiple instances and you can also use multiple keypairs on the same user on an instance.

like image 174
John Rotenstein Avatar answered Oct 21 '25 13:10

John Rotenstein


Yes, you can use one key pair for multiple EC2 instances. Click the "Launch" button and click "Choose an existing key pair."

enter image description here

like image 20
Ryland Goldman Avatar answered Oct 21 '25 13:10

Ryland Goldman