• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Mister PKI

SSL Certificates * SSL Tools * Certificate Decoder

  • PKI Training
  • OpenSSL
  • Keytool
  • PKI Tools
    • Apereo CAS
    • SAML
    • OpenID Connect
  • Get expert help

ssh ec2 instance – How to add an ssh key

November 16, 2023 by Mister PKI Leave a Comment

The purpose of this article is to demonstrate how to add an ssh key to an existing ec2 instance. If you are reading this then you have likely created an ec2 instance but cannot access it remotely except through the AWS console. It’s important to always have a way to ssh into your ec2 instances external from the AWS console. Make sure to secure the instance with security groups.

To create a key pair using Amazon EC2 you can follow the instructions here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html#having-ec2-create-your-key-pair

Alternatively you may create a key pair on the command line. We have written a previous article detailing how to generate your own key pair here with the ssh-keygen command.

After creating your key pair you will need to extract the public key from the private key if you do not already have it in a separate file. To extract the ssh public key from it’s corresponding private key run the following command.

ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub

Where -y -f will read the private SSH key file and generate the public key from it before outputting it to the specified public key file.

Next you will have to copy the new public key to your EC2 instance by first connecting to it through the AWS console. Paste the public key into the .ssh/authorized_keys file. Note that through your browser you much use CTRL v to paste the public key as right clicking to paste will not work.

Next, reload the sshd process with the following command:

systemctl reload sshd

You should now be able to ssh into the ec2 instance from the command line.

Conclusion – ssh ec2 instance

This article has demonstrated how to add an ssh key to an existing ec2 instance and then how to ssh into the ec2 instance from the command line with the new ssh key. Let us know in the comments if you have any questions or would like to see more examples of how to ssh into an ec2 instance.

AWS,  linux,  ssh

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Popular Posts

PKCS12

openssl s_client

Keytool

Keytool list

ECDSA vs RSA

OpenSSL

PKCS7

Certificate Decoder

PKI for DevOps Engineers – Free Training Series

PKI for DevOps Training Hub

Lesson 1 – How TLS and PKI Work

Lesson 2 – Understanding X.509 Certificates

Lesson 3 – Certificate Chains Explained

Lesson 4 – Debug TLS with OpenSSL

Lesson 5 – Verify Certificate Chains

Lesson 6 – Creating CSRs with OpenSSL

Lesson 7 – Working with PKCS12 Certificates

Lesson 8 – Java Keystores and keytool

Lesson 9 – Certificate Expiration Monitoring

Lesson 10 – Automating Certificate Renewal

Lesson 11 – Common TLS Errors

Lesson 12 – PKI Architecture for DevOps

Recent Posts

  • Apache mod_auth_cas: Protect Web Applications with Apereo CAS and Docker
  • Apache mod_auth_mellon: Configure SAML SSO & Docker
  • Configure OpenID Connect (OIDC) in Apereo CAS 7.3 and 8
  • Certificate Ownership Is an Operating Model Problem, Not a Tooling Problem
  • OpenSSL dgst: Create Checksums and Verify Digital Signatures

Footer

  • Twitter
  • YouTube
Mister PKI

Practical security engineering for the systems that establish trust.

Learn OpenSSL Keytool Free training
Work together PKI consulting CAS consulting Sponsored contributions
Site About Support Mister PKI Cookie policy Search
© 2026 Mister PKI Secure systems. Clear guidance.