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.
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.
There are two common methods for accessing a remote server’s graphical user interface:
- VNC, Virtual Network Computing, via SSH port forwarding.
- 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.
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@example.com
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.
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 firstname.lastname@example.org
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
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.
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@example.com
Now, run the xeyes application:
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.
Press ctrl-C on the AWS terminal window to kill xeyes.
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.