How to create an AWS EC2 instance
AWS is a cloud computing platform.
Amazon Ec2 ->Amazon Elastic Computer Cloud
First, what is the EC2 instance?
An EC2 instance is a virtual server that we can run our applications in AWS infrastructure.
Features of EC2 instance:
provide virtual computing environments
Secure login information for your instances using key pairs
Allow static IPv4 addresses for dynamic cloud computing
Steps to create an EC2 instance.
First, you need an AWS account. You can simply create it from AWS website and go to the create an account link.
Then click this link https://console.aws.amazon.com/ec2/ and go the Instances in the left pane. elect the instance and choose Launch Instance.
Then click EC2 and choose the AMI type according to the requirement. Then select the instance type (select free tire eligible. this will allow using the instance free.) Then Review and Launch -> Launch
After click Launch, it shows a new window asking Select an existing key pair or create a new key pair. If you have already created public and private keys you can use them. If not create a new key pair.
This key pair allows the securely access your instances using a private key instead of a password.
After that click launch instance and it will create a new instance for you.
when you right-click the instance it shows a popup. select connect to connect the instance and the instance is now ready to connect.
to connect the instance go to the SSH client and type following commands
chmod 400 your_key.pemssh -i "your_key.pem" user@public_ip_of_the_instance
This ssh connection allows for the port 22 only. Because the default port for the ssh is 22 and AWS instance automatically allows port 22.
To allow traffic on another port that 22, you must configure the associated security group and network access control list (network ACL).
Now you can connect via new port using this command
ssh -i "your_key.pem" user@public_ip_of_the_instance -p <new_port>
Import own public Key to AWS EC2
Instead of using Amazon EC2 key pair we can create RSA key pair locally and import the public key to Amazon EC2.
create RSA key (Linux):
ssh-keygen -t rsa -f my_rsa_key
save the public key to a local file
~/.ssh/my_rsa_key.pub
save the private key to a different local file with .pem extension
~/.ssh/my_rsa_key.pem
Now import that public key to the EC2.
EC2 console -> NETWORK & SECURITY -> Key Pairs -> import Key Pair -> Browse (select your public key) -> import
Now we can connect to the AWS EC2 connection without any key like this.
ssh user@public_ip_of_the_instance