I'm trying to run a program on an ubuntu 14.04 server instance on Amazon, but it needs a gui. I can install lunbuntu and use x2go to view the desktop, but as soon as there is a hiccup in my internet connection, x2go's connection drops and the desktop environment seems to shuts down (along with my program).

Is there a way to have the desktop running all the time on the instance and use x2go to access it (instead of it being created when I connect), so the desktop runs even if I lose my connection? The whole point of running it on EC2 is to have increased stability vs my sloppy connection.

After many hours on this problem with tons of reading and trying out different solutions to set the DISPLAY and xauth file, I can't seem to get it to work. Can it even be done?

  • 1
    What program are you running ? I suggest you use Freenx, it is fast and secure and should do as you envision.
    – Panther
    Feb 17 '16 at 16:57

Sure. There are two options:

  1. If you need to, occasionally, access the desktop, use vncserver:

    sudo apt-get install tightvncserver

    Note: there are other implementations, but this one will work fine. Once it's installed, run it:

    vncserver :1

    The first time you run that, it will ask for a password to access your desktop. Pick one. You can now access it using any VNC client. Note: the VNC protocol is not encrypted. You will want to tunnel it in some encryption (e.g., SSH port forwarding, or a VPN, or something along those lines), and firewall away its ports (in this example, that's port 5901).

  2. If you don't need to access the GUI, it just needs to run, you can use xvfb inside ascreensession:

    sudo apt-get install screen xvfb
    screen xvfb-run your_application

    This starts a screen session, which starts xvfb, which starts your application. screen is a program to allow you to start something, disconnect from it, and reconnect to it later. The disconnect is done by way of ctrl-a,d (that is, hold control and a, release both, press d); reconnecting is done with screen -r.

    xvfb-run is a script which starts Xvfb, which is short for "X for Virtual Framebuffer". It speaks the X11 protocol, but does almost nothing with it; whatever your application sends to that X server is not shown on any screen. It is still an X server, however; in order to be able to use it, you must set a few environment variables and do some Xauthority magic. xvfb-run exists so that you don't have to do that manually. Finally, after all that is set up, xvfb-run starts your application, and connects it to Xvfb for graphics and the terminal where you started it (in this case, your screen session) for stdout. Whenever your application disconnects from the X server, Xvfb (and by extension, xvfb-run) will exit.

Since Xvfb doesn't allow you to modify things, it requires less resources and may be faster. However, if you need to access the GUI, that's not an option.

  • Thanks for your detailed reply. I tried tightvnc before x2go but dropped it since it was not encrypted. I'll look into using SSH port forwarding to make sure it's secure. Don't want anyone snooping in on all the important stuff running on my instance ;)
    – Name
    Feb 17 '16 at 17:58
  • It seems that I can connect using the x2go client (which uses SSH) to the desktop created by vncserver. Thanks for your help!
    – Name
    Feb 17 '16 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.