AWS Introduction
AWS Pricing
AWS Threats
AWS Misconfigurations
- Getting Started with AWS Audit
- Permissions required for Misconfigurations Detection
- API Gateway Audit
- Cloudformation Audit
- CloudFront Audit
- CloudTrail Audit
- Cloudwatch Audit
- DynamoDB Audit
- EC2 Audit
- Elastic Search Audit
- ELB Audit
- IAM Audit
- KMS Audit
- Kubernetes Audit
- Lambda Audit
- RDS Audit
- Redshift Audit
- Route53 Audit
- S3 Audit
- Security Groups Audit
- SES Audit
- SNS Audit
- IAM Deep Dive
- App Sync Audit
- Code Build Audit
- Open Search Audit
- Shield Audit
- SQS Audit
Unused AWS EC2 Key Pairs Should Be Removed
More Info:
Unused AWS EC2 key pairs should be decommissioned to follow best practices.
Risk Level
Medium
Address
Security
Compliance Standards
AWSWAF
Triage and Remediation
Remediation
Sure, here are the step-by-step instructions to remediate the issue of Unused AWS EC2 Key Pairs Should Be Removed in AWS using AWS console:
-
Login to AWS console and navigate to the EC2 dashboard.
-
Click on the “Key Pairs” option from the left-hand side menu.
-
Review the list of key pairs that are available. Identify the key pairs that are not being used by any instances.
-
Select the unused key pairs and click on “Actions” button.
-
From the drop-down menu, select “Delete Key Pair”.
-
A confirmation window will appear, click on “Delete” to confirm the deletion of the key pair.
-
Repeat this process for all unused key pairs.
By following the above steps, you will be able to remediate the issue of Unused AWS EC2 Key Pairs Should Be Removed in AWS using AWS console.
Here are the step-by-step instructions to remediate the issue of unused AWS EC2 Key Pairs using AWS CLI:
- Open the AWS CLI on your local machine or EC2 instance.
- Use the following command to list all the available key pairs:
aws ec2 describe-key-pairs
- Identify the key pairs that are not in use and note down their key pair names.
- Use the following command to delete the unused key pairs:
aws ec2 delete-key-pair --key-name <key-pair-name>
- Replace
<key-pair-name>
with the actual name of the key pair you want to delete. - Repeat step 4 for all the unused key pairs.
- Verify that the unused key pairs have been removed by running the command in step 2 again.
Note: Before deleting any key pair, make sure it is not being used by any running instances. If it is being used, first remove it from the instance and then delete it.
Sure, here are the step-by-step instructions to remediate the misconfiguration of unused AWS EC2 key pairs using Python:
- Import the necessary libraries:
import boto3
- Create a boto3 EC2 client:
ec2 = boto3.client('ec2')
- Retrieve all the key pairs in the AWS account:
key_pairs = ec2.describe_key_pairs()
- Loop through the key pairs and check if they are associated with any running instances:
for key_pair in key_pairs['KeyPairs']:
key_name = key_pair['KeyName']
instances = ec2.describe_instances(Filters=[{'Name': 'key-name', 'Values': [key_name]}])
if len(instances['Reservations']) == 0:
print('Deleting key pair:', key_name)
ec2.delete_key_pair(KeyName=key_name)
- The above code will delete all the unused key pairs in the AWS account.
Note: Please make sure to test the code in a non-production environment before running it in a production environment.