How to run GUI applications on an Amazon AWS cloud server

In a previous post, I showed how easy it is to set up a remote server on Amazon’s AWS service. Now I would like see if I can run one or more of the open-source network simulators I’ve been using on this remote server. I want be able to access a network simulator from any device such as a personal computer, a tablet, or even a smart phone.

To accomplish this, I first need to install a Linux desktop environment on the remote Ubuntu server. Then, I need to set up the server and my client devices to allow the graphical user interface displayed on a remote server to be viewed on a local client.

In this post I will show how to install a Linux desktop (in this case, XFCE) and how to set up either VNC or X11 on a server and client.

Required software

Linux desktop

In this example, I chose to run the XFCE desktop environment on the Amazon AWS remote server because XFCE uses less resources than other desktop environments such as Gnome or KDE.

Remote-access methods

There are two common methods for accessing a remote server’s graphical user interface:

  1. VNC, Virtual Network Computing, via SSH port forwarding.
  2. The X Window System, via SSH display forwarding.

In this post, I will mostly discuss how to set up and use VNC. X11 display forwarding is already built-in to Linux so I will only cover it briefly.

Important: Create a new user-id

Create a new userid that has a password before continuing. Please see my previous post for the procedure to set up a new user.

Switch to this new user-id before continuing.

Install required software

We will install the XFCE Linux destop environment and a VNC server on the remote Amazon AWS server.

Software on local host (my laptop)

On my laptop computer, I install and use a VNC viewer application.

I chose to use xvnc4viewer, the default for Xubuntu (I use Xubuntu on my laptop. See the Ubuntu documentation for information about other VNC viewer applications.

To install xvnc4viewer, run the command:

Laptop:$ sudo apt-get install xvnc4viewer

Software on remote AWS server

Remember, we are using the new user-id brian I previously created, not the default userid ubuntu.

Login to the AWS server:

Laptop:$ ssh -i ~/Documents/Ubuntu-2-keypair.pem [email protected] 

Install the XFCE desktop and a VNC server:

AWS:$ sudo apt-get update
AWS:$ sudo apt-get install xfce4 vnc4server

Set up the VNC Server

Next, run the VNC server to set up the 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.

AWS:$ vncserver

When vncserver runs for the first time, it sets up a default configuration file and a log file. It displays the locations of these files on the screen.

Now, stop the vncserver application:

AWS:$ vncserver –kill :1

Edit the vncserver configuration file, ~/.vnc/xstartup. In this case, I use the nano text editor:

AWS:$ nano ~/.vnc/xstartup

Uncomment the first line. Add the lines unset DBUS_SESSION_BUS_ADDRESS and startxfce4 & after the second commented-out line (ignore the instructions in the file to uncomment both lines). Finally, comment-out the last two lines.

The xstartup file should now look like below:

#!/bin/sh

# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
# x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
# x-window-manager &

Save the file.

Reboot the server

Now, you may want to reboot the instance. It’s not necessary but I usually like to reboot after installing a lot of software on a system, just to give it a clean start.

One way to do this is to use the AWS console. Click on the instance and then use the Actions button. Choose Instance State and then Reboot.

Login using SSH port forwarding

I use SSH port forwarding because it allows me to connect from my laptop computer to the VNC server running on the Amazon AWS instance. Most firewalls allow SSH traffic to pass, but block VNC by default. This method will work in almost any environment, such as my home, my local library, or a coffee shop. Using SSH port tunneling is also a more secure way to access a VNC server.

From my laptop computer, login to the remote AWS server and enable SSH port forwarding using the following command:

Laptop:$ ssh -L 5901:localhost:5901 -i ~/Documents/Ubuntu-2-keypair.pem [email protected]

Then, on the AWS server, start the VNC server application

AWS:$ vncserver

New 'ip-172-31-59-15:1 (ubuntu)' desktop is ip-172-31-59-15:1

Starting applications specified in /home/ubuntu/.vnc/xstartup
Log file is /home/ubuntu/.vnc/ip-172-31-59-15:1.log

VNC Viewer

Now, because I am already forwarding VNC through an SSH tunnel using port tunneling, the address and display number for the remote vncviewer appear to be on our local machine.

Access the remote VNC server with the command:

Laptop:$ xvncviewer localhost:1

I will be asked for the VNC password you created on the remote server. Now, I see a window open that displays the XFCE desktop running on the remote AWS server.

XFCE desktop running on remote server, viewed on local laptop using VNC
XFCE desktop running on remote server, viewed on local laptop using VNC

In my case, I saw icons did not display in the file viewer application and in the launcher. I solved this by navigating from the Launcher to Settings → Appearance window and selecting a set of icons. This is a known bug with XFCE and VNC.

Troubleshooting the VNC Server

If things don’t work as planned, view the VNC server’s log file for clues to the problem.

The log file is in the folder ~/.vnc, on the remote AWS server.

One issue I ran into is I saw a grey screen with three check boxes in the upper left corner instead of an XFCE desktop. The VNC server did not start up properly.

I checked the log file and saw information that complained about the ICEauthority file permissions. I deleted the file then restarted vncserver, which then rebuilt the ICEauthority file. This fixed the problem in my case.

X Window System

An alternative way to run remote GUI applications is to use X Forwarding. To test X11 display forwarding, logout and login again using SSH. This time, use X display forwarding:

$ ssh -X -i ~/Documents/Ubuntu-2-keypair.pem [email protected]

Now, run the xeyes application:

$ xeyes

We should see the xeyes application appear to run on our local laptop. This shows that X11 apps can run on AWS and send their display to our local computer.

15
X11 application, xeyes

Press ctrl-C on the AWS terminal window to kill xeyes.

Conclusion

I set up the remote AWS server so it now runs a Linux desktop environment. I can display on my laptop computer the GUI from applications running on the remote AWS server using either VNC or X11.

In this post, I used my Linux laptop as the local client. In future posts, I will try to get other clients, such as my tablet or mobile phone, to connect to the remote server’s GUI.

26 thoughts on “How to run GUI applications on an Amazon AWS cloud server”

  1. Thanks for this posting I’m almost there however I’m using mac how would I get to the GUI on AWS?

    1. You need to install a VNC viewer app. Search on the App Store.
      I use the Screens app. It is expensive but it works.
      Mac has a built-in VNC viewer tool but I found it did not work well for me.

  2. I finally found what I need, AWS is killing everyone who wants to install GUI on EC2, especially Linux system. Take dinner first(hungry) and then come back to follow you step by step. Hope it would be OK.

        1. I used this a couple of years ago. It was pretty good although performance isn’t quite up to pure vnc levels. Actually using rdp on a Linux server gives five better performance or x2go or 92nd itself

  3. Hi Brian,

    Thank you for the post.
    I used VNC viewer in order to access my home workstation from laptop.
    Along the way I’ve faced several issues, but the main disappointing was that it didn’t work as well as I expected. I mean, performance in GUI applications was not acceptable for day to day usage.
    I wonder how it works on Amazon. Have you used xterm after installation? If yes how good or bad it was?

  4. Hi Brian,

    looking for solution to connect via X-Windows and start a desktop manager. Somehow couldn’t get it running. Any suggestions how to do it ?

  5. Wow, I spent ALL DAY trying like 10 different tutorials on this. This is the only one I got to work. For your next trick, do a tutorial on how to run Unity this way.

    1. Hi Jim,
      Thank you. I also experience the same frustrations you did so that’s why I created this tutorial.
      Currently, I don’t plan to do an Ubuntu tutorial because I am using the free version of an Amazon EC2 instance so I use a desktop that is less resource-hungry.
      Brian

  6. This is great, but when starting vncserver, I get the following error message:

    xauth: (stdin):1: bad display name “ip-172-30-0-242:1” in “add” command

  7. Pingback: Amazon EC2 Ubuntu Server with GUI – N7IHQ Blog

  8. I followed as you told but i did not get vnc gui to my laptop. the vnc viewer tells like this message, “Time out waiting for a response from the host computer”

  9. There is a small typo, or things work differently from a Mac: when connecting to the server through the tunnel, you need to connect to localhost:5901, since this is the port you forward the remote port to.
    Just as a side note: On a Mac, type “inc://localhost:5901” into the address bar of a Safari browser window to bring up the in-built vnc screen sharing tool.

  10. Very nice post. I just stumbled upon your blog and wished to say that I’ve truly enjoyed surfing around your blog
    posts. In any case I will be subscribing to your feed and I hope you write again soon!

  11. Hi Brian,
    Is there a way to have the vncserver constantly running without having to SSH from the shell each time?

    Thanks

Comments are closed.

Scroll to Top