How to access AWS EC2 instance with SSH using Powershell from Windows OS.
PuTTY, a free and open-source terminal emulator, is one of the great tools used to SSH into an AWS EC2 instance and it is commonly used for this purpose.
I just realised recently that the task automation and configuration management program called Powershell from Microsoft is well suited for easy access into an EC2 instance without downloading any third-party application and subsequent necessary configuration for access.
Let’s explore this by showing a few steps to achieve this.
Step 1: Create Key Pairs
Let’s create a keypair from the AWS Management console. Search for EC2 from the services search box on the Management console and click on EC2, locate the ‘Key Pairs’ link from the left menu bar. This is under the “Network & Security” menu as shown below.
Select the link and click on “Create key pair” button.
Give it a name. I will call it “ssh-ec2key”. Ensure the “key pair type” is “RSA” and “.pem” is selected under the “Private key file format”. Click “Create key pair” button. The result should look like the below screenshot. Note that two keys will be generated, a public key as shown below and a private key to be downloaded to your PC which will be needed to ssh into the EC2 instance later.
Step 2: Navigate to the path of the private key
From the Powershell, ensure that you navigate to the path of the downloaded private key. My “ssh-ec2key.pem” is located in my “download” folder in this path on my PC.
Step 3: Create the EC2 instance.
Select “EC2 Dashboard” and click “Launch instance”, give it a name. For example “My EC2 Instance”. Select “Amazon Linux 2 AMI…Free tier eligible”, “t2.micro free tier eligible” instance type. Select the key pair name as required(the public key). Select the default “vpc” and “subnet” under “Network settings”. Under “Firewall”, create a new security group. Select “Allow SSH traffic from” “My IP” (Here your ISP assigned IP will appear as an option to be selected). Accept the default storage configuration and click “Launch instance”.
Grab the assigned Public IPv4 address as this will be used for the ssh access. Launch the powershell and ensure you are in the path of the private key, type this command from the terminal and hit the enter key.
ssh -i ssh-ec2key.pem ec2-user@34.201.120.190
Type “exit” command from the terminal to close this connection and terminate your EC2 instance to stop unnecessary charges.
This can also be achieved by using windows command prompt (CMD).
I hope this has been informative and I will see you in the next one. Cheers!