How to create Amazon EC2 instance and perform login using SSH
Login to the management console
- Login to the EC2 management console:
- From the upper pane, it is strongly recommended to select a region close to your location
- Note: There might be pricing differences between AWS regions. For more information, see:
- https://aws.amazon.com/ec2/pricing/
- From the left pane -> Instances -> Instances -> click on “Launch Instance” -> select the relevant Amazon Machine Image.
- From the “Choose an Instance Type”, select machine type according to your needs.
- For more information, see:
- https://aws.amazon.com/ec2/instance-types/
- Click on “Next: Configure Instance Details”
- Configure Instance Details page:
- Number of instances – unless you need redundancy, leave the default value
- Purchasing option - In case you do not need permanent EC2 machine for development / test environments, and would like to save money, consider using EC2 spot instance. For more information, see:
- Network – Select the relevant VPC (Virtual Private Cloud). For more information on creating a VPC, see:
- Subnet – Select the relevant subnet and availability zone. For more information on creating subnets, see:
- Auto-assign Public IP – Leave the default settings
- IAM role - Choose the relevant Amazon IAM role. For more information on creating IAM roles, see:
- Shutdown behavior – Choose either Stop (the instance will be shut down, but it’s content will remain) or Terminate (the instance content will be permanently removed)
- Enable termination protection – This option protect the instance content from been permanently removed when selecting “Terminate instance” from the management console. This option is not relevant for Spot instances
- Monitoring – Allows you to monitor the performance of the instance; however, there is additional cost for using this service. For more information, see:
- Tenancy – Leave the default settings (unless you have specific requirement, at additional cost, to choose a dedicated hardware without sharing it with other customers)
- Network interfaces – Leave the default settings
- Advanced Details – under “User data”, you can specify post-login script (for example, update security patches, install additional components, etc.)
- Click on “Next: Add Storage”
- From the “Add Storage” page, feel in the following details:
- Specify the root device volume size
- Select the Volume type according to your needs. For more information, see:
- In case you need additional storage (for example, split between OS drive and data drives), click on “Add New Volume”
- When adding additional volumes, it is recommended to encrypt all the additional volumes (there is no performance impact)
- Click on “Next: Add Tags”
- Click on “Add Tag”:
- Key – Specify here ”Name”
- Value – Specify here the instance host name
- It is recommended to add additional tags (such as project name, environment, etc.). For more information, see:
- Click on “Next: Configure Security Group”
- From the “Configure Security Group” page, select either to create a new security group or to select an existing security group.
- When creating a new security group, specify an informative “Security group name” and description.
- When configuring security groups for publicly accessible EC2 instances, it is highly recommended to avoid opening SSH / RDP access from the internet to the EC2 instances – restrict access to the EC2 instances from a static public IP address or your organization public address/subnet
- Click “Review and Launch” -> click on Launch
- On the “Select an existing key pair or create a new key pair” page:
- “Create a new key pair” and specify key pair name – if this is your first EC2 instance in this specific region -> click on “Download Key Pair” to download the private key file -> save this key in a secure location, since it allows access to your EC2 instances
- “Choose an existing key pair” – if you already created and download the private key file, select an existing key pair -> click on “I acknowledge”
- Click on “Launch Instances” -> click on “View Instances”
- Wait for the EC2 instance to switch its state to “running”
Login to EC2 instance (from Windows machine)
- Download puttygen.exe from:
- Run the puttygen.exe
- Click on “Load” -> change the file extension from “Putty Private key files” to “All Files” -> locate the private key pair and click on Open -> click on OK -> click on “Save private key” -> click on “Yes” -> save the private key file with PPK extension -> close puttygen.exe
- Download Putty from:
- Run putty.exe
- From the left pane, under “Connection” -> expand SSH -> click on “Auth” -> from the main pane, under “Authentication parameters”, click on “Browse” -> locate the SSH private key generated by puttygen.exe
- From the left pane, click on “Session” -> from the main pane, under “Host Name (or IP address)” specify the following:
- ec2-user@IP_Address
- Note: Replace IP_Address with the EC2 instance “IPv4 Public IP” or “Public DNS (IPv4)”
- Under “Saved Sessions”, specify a name for this newly created connection.
- Click on Save
- Click on Open
Login to EC2 instance (from Linux machine)
- Login to the Linux machine console.
- Copy the private key file into ~/.ssh of the currently running user
- Run the following command:
- ssh ec2-user@IP_Address -i ~/.ssh/[KEY_FILENAME]
- Note 1: Replace IP_Address with the EC2 instance “IPv4 Public IP” or “Public DNS (IPv4)”
- Note 2: Replace KEY_FILENAME with the actual private key file name