GUI using VNC with Amazon EC2 Instances

Amazon ec2 Instances (a.k.a. Virtual Machines) are an amazing resource for any developer these days and regardless of why you use them it can’t be denied they are really fun and astonishingly powerful.

As someone who loves playing with cloud computing resources and virtual machines, I wanted to have a GUI and basically use my virtual machine as a computer. When I finally figured out a simple way It felt like discovering a whole new world. And I would like to share it with you.

You can use Virtual machines with GUI using these simple steps

  1. Set up an instance following these instructions. This example is tested on Ubuntu instance and hopefully should work on most other OS.
  2. Download and install Realvnc or any other VNC client.
  3. SSH into the instance and type these commands

Now this will take some time but it’s totally worth the wait. After that do

This, helps to set up the VNC configuration. It will ask you to create a VNC password. Choose your password and enter it at the prompt, then enter it a second time to verify.
Now edit ~/.vnc/xstartup file and replace all the contents with the lines below.

Now logout of the instance and login into the instance again using port forwarding. Your command should look something like

Now start a new vncserver

NOTE: Here I 1340x750 refer to my desktop dimensions. You can adjust these values based on your own screen size.

Now use Realvnc to connect to localhost:5902 and enter the password you wrote above.(there is a correlation between them (eg. display 1 = vnc port 5901, 6001 and display 2 = vnc port 5902 etc)

Now you can enjoy your virtual machine with GUI.

NOTE: once you have performed these steps once all you need is ssh and Realvnc on your computer to work with this. So you can use VNC not just from your own computer but any computer anywhere across the world. All you need is a VNC client and your access key to use this from anywhere.

I hope you liked this post. Any suggestions and recommendations are very welcome.

Have a great day!!!