AWS Command line Tasks - Create SSH key pair, security group, Allow connection to a port
We need a working aws cli configured to use the following commands.
To create an SSH pem file.
aws ec2 create-key-pair --region us-east-1 --key-name mysshkey --output text > mysshkey.pem
region : The region in which the ssh pem file is getting created.
Here we are saving the pem file in our linux machine as the name mysshkey.pem
Modify the permission of the pem file.
chmod 400 mysshkey.pem
To create a security group.
aws ec2 create-security-group --region us-east-1 --group-name work_project --description "Project_for_work" --vpc-id vpc-12345
group name - It is the name that we are going to give for the security group
description - The description that we are going to give for the security group
To allow connection to a port
aws ec2 --region us-east-1 authorize-security-group-ingress --group-id sg-12345 --protocol tcp --port 22 --cidr 10.100.0.0/16
aws ec2 --region us-east-1 authorize-security-group-ingress --group-id sg-12345 --protocol tcp --port 22 --cidr 10.150.0.0/16
The port :--protocol tcp --port <port number here>
Allowing IP or IP range : --cidr <IP range or the IP>
To create an SSH pem file.
aws ec2 create-key-pair --region us-east-1 --key-name mysshkey --output text > mysshkey.pem
region : The region in which the ssh pem file is getting created.
Here we are saving the pem file in our linux machine as the name mysshkey.pem
Modify the permission of the pem file.
chmod 400 mysshkey.pem
To create a security group.
aws ec2 create-security-group --region us-east-1 --group-name work_project --description "Project_for_work" --vpc-id vpc-12345
group name - It is the name that we are going to give for the security group
description - The description that we are going to give for the security group
To allow connection to a port
aws ec2 --region us-east-1 authorize-security-group-ingress --group-id sg-12345 --protocol tcp --port 22 --cidr 10.100.0.0/16
aws ec2 --region us-east-1 authorize-security-group-ingress --group-id sg-12345 --protocol tcp --port 22 --cidr 10.150.0.0/16
The port :--protocol tcp --port <port number here>
Allowing IP or IP range : --cidr <IP range or the IP>
Comments
Post a Comment