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

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Create and Remove AWS EC2 key pair by using command line

March 9, 2015 by Sharad Chhetri

When we launch a new EC2 instance in AWS Cloud , to access the server we need the ssh keys. In EC2 instances password are not set , we have to use ssh key to get access whereas keys are based on public–key cryptography.

Here, we are quickly going through with creating/removing/listing the ssh keys by using command line. We will do this practice by using AWS cli with AWS Access key set on your system .
(http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html)

Create AWS ssh key by using aws command line

Generally we use the below command so that the .pem file will be created directly to your working directory.

Replace the below given values in command –
1. us-east-1 ## with region where you want to create keys
2. my-aws-key ## Give your desired key name

aws --region us-east-1 ec2 create-key-pair --key-name my-aws-key --query 'KeyMaterial' --output text > my-aws-key.pem

When we use above command , the .pem file will be get created.

Now, give 400 permission to aws key file (.pem file)

chmod 400 my-aws-key.pem

List AWS ssh keys by using aws command line

To list the AWS ssh keys are very simple.
Replace us-east-1 with region name you want .

aws --region us-east-1 ec2 describe-key-pairs

Remove the AWS ssh key by using aws command line

First list the AWS ssh key available as we have described in above section. To remove the ssh key, use below given command.
Replace us-east-1 with your given region name and my-aws-key with your aws ssh key (Listed from above given command).

aws --region us-east-1 ec2 delete-key-pair --key-name my-aws-key

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. How to set Name of EC2 instance by aws cli
  2. Attach security groups to existing instance with AWS cli
  3. Exam Tips : AWS Certified Solutions Architect – Associate
  4. How to mount s3 bucket in linux EC2 instance
  5. Be carefull while using phpinfo script in EC2 beanstalk
  6. How to enable direct ssh to EC2 linux instance without keypair file
  7. Create bootable usb key for CentOS 7 installation
  8. vi : remove space at beginning and end of each line
  9. How to create Jenkins user by command line and GUI
  10. grep command to remove commented lines

Filed Under: AWS Tagged With: aws

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

How to convert float to integer number

How to hide php version information in header

safest method to remove softlink in linux

Nagios HTTP WARNING: HTTP/1.1 403 Forbidden

SSH WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED

Keep logs of user after sudo su – : Secondary Logging

Change the default port number of ssh server

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ·
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy