How to connect to AWS EC2 ubuntu GUI using PUTTY from the windows machine?
This article includes the steps of creating an Amazon AWS Ubuntu instance, setting up a desktop GUI via PUTTY, and connecting to it via Remote Desktop Connection.
So let’s get started,
We will start by creating an EC2 instance. Go to EC2 Console https://console.aws.amazon.com/ec2/v2/home and Click on Launch instance. Where you will find multiple AMIs, Scroll down and select Ubuntu Server (For testing purpose select Free tier eligible).
Once you select the server, follow further steps, and launch. Make sure while launching download the PEM file as it will need in the future.
Now go to the EC2 dashboard and look for a public IP address and Copy that as we will need for PUTTY configuration, Though you can use Public DNS as well.
We are done with AWS configuration, now open PUTTY and follow a few steps:
- Add copied IP address in the Host Name field and name the Saved session and save it. Will keep port as it is i.e., 22 as we have only opened the 22 port as we want everything should go through the SSH tunnel; though you can open other ports as well there will be less security.
- Add SSH (PPK) key by browsing SSH -> Auth -> Private Key file for authentication -> Browse and again go to Session and Save it.
Note: By default, AWS only provide a PEM file. We need to convert PEM to PPK. You can find multiple online tools for converting this.
- Click on Open, and it will prompt security alert just choose Yes, and you will able see the command prompt.
- On the command prompt, just log in as Ubuntu, as we have added PPK so it won’t ask for Password.
- Once you get logged into the server, you need to follow the below.
- sudo apt update && sudo apt upgrade
- sudo sed -i ‘s/^PasswordAuthentication no/PasswordAuthentication yes/’ /etc/ssh/sshd_config – To set login credentials
- sudo /etc/init.d/ssh restart
- sudo passwd ubuntu – This will be your login password to ubuntu machine
- sudo apt install xrdp xfce4 xfce4-goodies tightvncserver
- echo xfce4-session> /home/ubuntu/.xsession
- sudo cp /home/ubuntu/.xsession /etc/skel
- sudo sed -i ‘0,/-1/s//ask-1/’ /etc/xrdp/xrdp.ini
- sudo service xrdp restart
Note: In between, if this process asks for some kind of choice, then select the local version installed option.
Now, we need to configure the tunnel on PUTTY to the route of the request.
Open PUTTY again and go to the Connection – > SSH -> Tunnels ->
- Add Source Port (This could be any in my case I have added 8888).
- Add Destination Port – This will be your instance private IP address following with 3389.
- Click on Add.
Once done, now click on the open button and you will see a Command prompt where login Id will be Ubuntu.
Now you can check either we are listening on the same port or not using the following command: netstat -antp
Now we are done with the setup.
Open Remote Desktop Connection
Add localhost:8888 or 127.0.0.1:8888 and Connect
You will be asked for username and password; So username could be Ubuntu and Password will be added by you while installing the command. And Yeah, there you go, We have successfully logged into the Remote server.