Setting up GUI for Amazon EC2 ubuntu instance
Amazon EC2 provides a wide selection of instances for different use cases. While it’s common practise to use SSH for connecting to an EC2 instance, Sometimes graphical interface might be come in quite handy if you are new to linux and need a straight forward way for your data setup, file transfers and editing your code.
In this tutorial, I would like to share a simple steps for setting up a GUI in your EC2 instances. If you need instructions for setting up an EC2 instance, Please check out my previous post on AWS EC2 setup. Assuming that you have already an EC2 instance setup in AWS website, Lets get started with the steps for setting up the graphical interface.
Firstly, connect to the EC2 instance you have created using command line.
$ ssh -i key.pem email@example.com
Type the following commands to install vncserver.Also,Type in ‘Y’ when ever prompted.
$ sudo apt-get update $ sudo apt-get install ubuntu-desktop vnc4server gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal
Now, Let’s start the vncserver we have installed and enter a password for vncserver.
you should be notified with a startup log file creation as below
Creating default startup script /home/ubuntu/.vnc/xstartup
Starting applications specified in /home/ubuntu/.vnc/xstartup
Log file is /home/ubuntu/.vnc/ip-yourip:1.log
If you see the message as shown above, it implies that the vncserver is running. Now, Let’s stop the vncserver to make a few changes to xstartup file
$ vncserver -kill :1
For making changes to the xstartup file, Navigate to the file using the commands below and make changes using vim
$ cd .vnc $ sudo vim xstartup
After the editor is open, Comment out the code in xstartup file and add the code given below
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrbd $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
After copying the code, save and exit the file. The setup required for the GUI is now complete. Now, It’s time to exit out of ssh instance and connect again for tunneling it to a port.Connect to ssh now using the below command.
$ ssh -L 5901:localhost:5901 -i key.pem firstname.lastname@example.org
Once you are connected to your instance, Kill the vncserver and then connect back using the resolution settings as below
$ vncserver -kill :1 $ vncserver -geometry 1920x1080
The vnc server is now running on your EC2 instance. Let’s install and connect to the vncviewer in our local computer.
VNC Viewer Download link: https://www.realvnc.com/download/viewer
Once VNC viewer is installed, Connect using the address “localhost:5901” and password which you have setup earlier.
Now you should be able to see the ubuntu GUI for you Amazon instance. Hope you have found this article helpful. Do post below in case you have any issues or comments.Thanks!!