Tech Kraft

Documentum, AWS, Java, Ruby on Rails, Linux, Windows, App Servers


How To Add Multiple Key Pairs to AWS EC2 Instance

Step 1: Create Additional Key Pairs

Each user that needs access to the EC2 instance should have a unique key pair. Create a key pair using the following command:

aws ec2 create-key-pair --key-name MySecondKeyPair --query 'KeyMaterial' --output text > MySecondKeyPair.pem

Remember to replace MySecondKeyPair with your desired key pair name. Repeat this step for as many key pairs as you need.

Step 2: Add Public Keys to the EC2 Instance

Next, add the public keys of the additional key pairs to the ~/.ssh/authorized_keys file on the EC2 instance.

First, extract the public key from the private key file:

ssh-keygen -y -f MySecondKeyPair.pem > MySecondKeyPair.pub

Then, copy the public key to the EC2 instance:

ssh -i MyKeyPair.pem ec2-user@<Your-EC2-Instance-IP> "echo 'cat MySecondKeyPair.pub >> .ssh/authorized_keys'"

Repeat this step for each additional key pair.

Test SSH Access

Finally, test SSH access with the new key pair:

ssh -i MySecondKeyPair.pem ec2-user@<Your-EC2-Instance-IP>

If everything is set up correctly, you should be able to log in to the EC2 instance with the new key pair.



Leave a comment

About Me

Senior Software Engineer professional with over 16 years of success with multiple open source technologies and various Content Management platforms and solutions.

Proven technical abilities through numerous projects involving enterprise web application design and development, application installation, configuration and support, and workflow and collaboration system designs.

  • Ability to learn new technologies and platforms quickly and apply them to the task at hand.
  • Excellent analytical skills, and strong communication and collaboration abilities.
  • Technical emphasis in including but not limited to Java, Ruby on Rails, Documentum and Alfresco
    in both Linux and Windows based environments

Newsletter