Connect to EC2 from Windows WSL

Sudheer Kumar
2 min readAug 1, 2020

To connect EC2 instance from Windows, you have a number of options. You can use a tool called PUTTY, can use a Chrome secure shell app. Here I am going to use Ubuntu running on Windows to connect to an EC2 instance. I am writing an article as I didn’t find many resources on this.

The below article tells how to install WSL (Windows Subsystem for Linux) on windows:

Now you need to download the *.pem file from AWS Console to a location on your windows mahine.

  1. On the Linux home folder, create a new folder : pems
  2. Copy the pem file from windows to your Linux home folder : C:\Users<user_id>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\<linux_username>
  3. >cd pem
  4. See the current privileges of the file, you can see it has all access.
  5. Restrict the privilege to read-only to protect the file. You can connect to SSH after this step. >chmod 400 greatlearning.pem
  6. Now connect to your EC2 instance: >ssh -i mine.pem ubuntu@<public.ip.address>

You can get this url from AWS console, select your EC2 instance and click : Connect button and you will see the SSH command to connect to this instance.

You will be prompted for confirmation and after that, you are on the EC2 instnace:

The following are some of the sample commands you can do on EC2 instance. I have created an Ubuntu EC2 instance:

· $sudo apt update (update repositories, Linux Debian family)

If an amazon EMI Linux (CentOS family) or Amazon AMI linux, the command will be:

$sudo em update

· Install Apache2 webserver:

$sudo apt install apache2

· Start the service and check status

$sudo service apache2 start

$sudo service apache2 status

· Ping localhost

$curl localhost

--

--

Sudheer Kumar

Experienced Cloud Architect, Infrastrcuture Automation, Technical Mentor