In this article, we will learn how to create a Security Group
, that enables SSH traffic through port 22 from a Managed Prefix List
. The Managed Prefix List
allows us to conveniently manage your public IP-addresses that can connect to our EC2 instance
.
Table of Content
- Create Managed Prefix List
- Create Security Group
- Attach Security Group to EC2 instance
- Access your EC2 instance via SSH
- Conclusion
1. Create Managed-Prefixlist
- Go to the AWS service
VPC
and selectManaged prefix lists
. - Click the button
Create prefix list
Prefix list name
: IP-Whitelist for SSH accessMax entries
: 10Address-family
: IPv4- Under
Prefix list entries
click Add new entry - Click Create prefix list
2. Create Security Group
- Go to the AWS service
VPC
and selectSecurity groups
. - Click Create security group
Security group name
: SSHDescription
: Allows SSH access from a managed prefix listVPC
:- Under
Inbound rules
click Add rule Type
: SSHSource
: Custom- Scroll down to Prefix lists and select your created newly created IP-Whitelist for SSH access prefix list.
- Click Create security group
3. Attach Security Group to EC2 instance
- Go to the AWS service
EC2
and select yourEC2 instance
- Go to
Actions
->Security
and clickChange security groups
- Under Associated security groups select your newly created Security Group
SSH
- Click Add security group
- Click Save
Now you should be able to connect via SSH
to your EC2 instance. Of course you also need a valid Key pair
assigned to your EC2 instance
and have the corresponding private key on your local machine or client.
4. Access your EC2 instance via SSH
- Go to the AWS service
EC2
and select yourEC2 instance
. - Make sure under
Details
->Key pair assigned at launch
you have aKey pair
assigned and you have the correspondingPrivate Key
(usually a .cer file) saved on your local machine. - On your local machine open a new
terminal
and navigate to yourPrivate Key
cer file. - Connect to your
EC2 instance
with following command
Replace the ip-address 10.20.30.40 with your Public ip-address of yourssh -i privateKey.cer ubuntu@10.20.30.40
EC2 instance
and ubuntu with your user.
5. Conclusion
In this article we learned how to create a Managed prefix list
to simplify the process of adding and modifying IP addresses that are permitted to establish an SSH
connection to our EC2 instance
. We have also covered the steps involved in creating a Security Group
and configuring an Inbound rule
specifically designed to allow SSH
access via Port 22
from our newly created Managed prefix list
. By assigning this Security group
to our EC2 instance
, we have successfully established SSH
connectivity, provided that we have a valid Key pair
associated with our EC2 instance
and have saved the corresponding Private Key
on our local machine or client.