AWS Key Pairs
What is AWS Key Pairs
AWS key pair is basically used to login EC2 instance without using password in a secure manner.When we create EC2 instance, need to provide key file name, At this time Amazon EC2 instance will store public key at server in ~/.ssh/authorized_keys file and you store private key at your machine. Only using this private key you can login to the instance.
you can add or replace key pair with your running instance.
The keys that Amazon EC2 uses are 2048-bit SSH-2 RSA keys. You can have up to five thousand key pairs per region.
Creating AWS Key Pair
1. Using AWS Console
2. Using CLI
3. Importing your Own Key Pairs using AWS Console
4. Importing your Own Key Pairs using AWS CLI
1. Using AWS Console
- navigation pane, under NETWORK & SECURITY, choose Key Pairs
Fig1 Select Key Pairs - Chose Create key pair
fig 2 Create Key Pair - Enter key pair name, and click on create this will create key pair and download private key at your system. Keep this file at secure place and change its permission to readonly using chmod 400
Fig 3 Enter key pair name
Fig 4 After Creating Key Pair
2 Using CLI
create-key-pair
--key-name <value>
[--dry-run | --no-dry-run]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
for example
aws ec2 create-key-pair --key-name test2
3. Importing your Own Key Pairs using AWS Console
1. Generate key pair using any keygen tool such as ssh-keygen Note AWS does not support DSA key format
2. Save public key to a local file by extension .pub
3. save private key to a local secure area by extension .pem
4. open AWS management console and navigate Network Security open Key Pair
Now click on Import Key Pair
5. Select public key file
4. Importing your Own Key Pairs using AWS CLI
import-key-pair
[--dry-run | --no-dry-run]
--key-name <value>
--public-key-material <value>
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
for example
aws ec2 import-key-pair --key-name mypublickey --public-key-material MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuhrGNglwb2Zz/Qcz1zV+l12fJOnWmJxC2GMwQOjAX/L7p01o9vcLRoHXxOtcHBx0TmwMo+i85HWMUE7aJtYclVWPMOeepFmDqR1AxFhaIc9jDe88iLA07VK96wY4oNpp8+lICtgCFkuXyunsk4+KhuasN6kOpk7B2w5cUWveooVrhmJprR90FOHQB2Uhe9MkRkFjnbsA/hvZ/Ay0Cflc2CRZm/NG00lbLrV4l/SQnZmP63DJx194T6pI3vAev2+6UMWSwptNmtRZPMNADjmo50KiG2c3uiUIltiQtqdbSBMh9ztL/98AHtn88JG0s8u2uSRTNEHjG55tyuMbLD40QEXAMPLE
Replace Key Pair with New One
Connect to your instance using your existing private key file.
Using a text editor of your choice, open the .ssh/authorized_keys file on the instance. Paste the public key information from your new key pair underneath the existing public key information. Save the file.
Now connect using new private key.
No comments:
Post a Comment