Logging into EC2 Instances Without a .pem File: Alternative Authentication Method (2024)

Logging into EC2 Instances Without a.pem File: Alternative Authentication Method (2)

One way to connect an ec2 instance is executing this command:

ssh -i /path/to/your/key.pem [email protected]

Everytime when you login, you have to specify the path key.pem(private key) file. However, by performing few easy peasy steps, we can shorten the above command to:

ssh [email protected]

That means no need to keep pem file locally. One more advantage is, often times we use the same key-pair while creating new EC2 instance. And if we share the .pem file with a user, then they are open to connect to all the running EC2 instances(which is completely unnecessary). So rather than distributing private key file each users, admin/root user can perform the below stated method and the other user can login(restricted to required EC2 instance) without pem file .

1. Generate a SSH key pair on your local system

Open your terminal, and execute below command. Below command generates SSH key on Linux and MacOS.

ssh-keygen -t rsa

The -t flag specifies the type of key to generate, and rsa is the specific type of key being requested. RSA (Rivest-Shamir-Adleman) is a oldest and widely used public-key cryptosystem, known for its strong encryption and digital signature capabilities.

Instead of RSA, we can also generate ECDSA (Elliptic Curve Digital Signature Algorithm) key pair by specifying -t ecdsa. However, RSA keys are generally the most widely supported and commonly used for SSH authentication.

You will be prompted to enter filename(which is optional), it is asking where you want save the private key. If you keep it empty and press enter, then they keys will be saved at home_directory/.ssh/id_rsa

Logging into EC2 Instances Without a.pem File: Alternative Authentication Method (3)

2. Copy the public key

Once the key pair is generated, you can view the public key using this command:

cat ~/.ssh/id_rsa.pub

Copy the content displayed on the terminal.

3. Login to EC2 instance

For one last time, just connect to your EC2 instance using the .pem file. And perform the following steps:

a) Make .ssh directory(if not present) in the current directory: mkdir ~/.ssh

b) Set the required folder permisson: chmod 700 ~/.ssh

c) Copy your public key from step-(2) inside an authorized_keys file.

echo "your public-key" >> ~/.ssh/authorized_keys

We don’t have to create authorized_keys files explicitly, the above command will create the required file and copy the content.

It is also possible that, .ssh folder already exists in your root directory. And authorized_key file already exists. Then just execute command given in (3.c)

d) Exit the EC2 instance and connect back using this command:

ssh [email protected]

In this brief blog post we saw how to log into an EC2 instance without being dependent on a private key file (.pem file).

PS: I will be publishing more short blogs similar to this. As, I use short blogs as a way to retain my knowledge, understanding, or something I recently learned or discovered, so that I may refer to it at any time in the future and anyone else can use it as well.

Logging into EC2 Instances Without a .pem File: Alternative Authentication Method (2024)
Top Articles
Mark Cuban says this was always his ‘driving motivation’—and it’s not money
Malaysia Budget Travel – When and Where to Go and How Much It Will Cost
Rubratings Tampa
Craftsman M230 Lawn Mower Oil Change
Pga Scores Cbs
Z-Track Injection | Definition and Patient Education
New Day Usa Blonde Spokeswoman 2022
Luciipurrrr_
[2024] How to watch Sound of Freedom on Hulu
The Weather Channel Facebook
Wordscape 5832
Fear And Hunger 2 Irrational Obelisk
Rhinotimes
Uc Santa Cruz Events
Www Craigslist Com Phx
Aspen Mobile Login Help
Everything you need to know about Costco Travel (and why I love it) - The Points Guy
Missed Connections Inland Empire
Moving Sales Craigslist
Craigslist Pet Phoenix
Finalize Teams Yahoo Fantasy Football
Allybearloves
Bekijk ons gevarieerde aanbod occasions in Oss.
Conan Exiles Sorcery Guide – How To Learn, Cast & Unlock Spells
Homeaccess.stopandshop
Lost Pizza Nutrition
Bellin Patient Portal
Jermiyah Pryear
Bolsa Feels Bad For Sancho's Loss.
WRMJ.COM
13301 South Orange Blossom Trail
R Baldurs Gate 3
Log in to your MyChart account
Wheeling Matinee Results
Justin Mckenzie Phillip Bryant
Strange World Showtimes Near Atlas Cinemas Great Lakes Stadium 16
Help with your flower delivery - Don's Florist & Gift Inc.
Western Gold Gateway
3496 W Little League Dr San Bernardino Ca 92407
Überblick zum Barotrauma - Überblick zum Barotrauma - MSD Manual Profi-Ausgabe
Gold Dipping Vat Terraria
How To Upgrade Stamina In Blox Fruits
Kb Home The Overlook At Medio Creek
Amateur Lesbian Spanking
Sapphire Pine Grove
Automatic Vehicle Accident Detection and Messageing System – IJERT
Cvs Minute Clinic Women's Services
Superecchll
How To Connect To Rutgers Wifi
Famous Dave's BBQ Catering, BBQ Catering Packages, Handcrafted Catering, Famous Dave's | Famous Dave's BBQ Restaurant
Laurel Hubbard’s Olympic dream dies under the world’s gaze
Obituary Roger Schaefer Update 2020
Latest Posts
Article information

Author: Delena Feil

Last Updated:

Views: 6082

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Delena Feil

Birthday: 1998-08-29

Address: 747 Lubowitz Run, Sidmouth, HI 90646-5543

Phone: +99513241752844

Job: Design Supervisor

Hobby: Digital arts, Lacemaking, Air sports, Running, Scouting, Shooting, Puzzles

Introduction: My name is Delena Feil, I am a clean, splendid, calm, fancy, jolly, bright, faithful person who loves writing and wants to share my knowledge and understanding with you.