Using NX to Run GUI Applications From a Linux Server
While Linux servers don’t typically run graphical user interfaces (GUIs) they are just as capable of doing so as any other computers, and there are certain situations in which serving up GUI applications over the network may be necessary or desirable.
In fact, the still standard X11 display server for Linux was designed with the capability to serve up graphical interfaces over the network. This is actually one method of running GUI applications remotely from a server; X11 forwarding over SSH with the X11 server running on the client machine and SSH forwarding X11 dependent applications to it. Another common method is VNC (Virtual Network Computing), but it can be pretty slow.
One solution which offers a lot of flexibility and speed is NX from NoMachine. While there is a paid solution they do offer a paid solution, and it works brilliantly. If you have a server, either a local one at home, a VPS or a dedicated remote server, here’s how you can set it up. This guide is centered around Ubuntu, but in principle should apply to most Linux distributions.
1. Download and install the NX client
It is available for Windows, OS X, and various Linux distributions:
2. Download and install the NX server and NX node to your server
Now that you’ve got the client you need to install the NX server software to connect to. Log in to your server, download the NX server and NX node packages, and install them.
All Linux downloads are here. Ubuntu and Debian packages are here. You can use the wget -c command to download the packages directly to your server from the command line. Get the direct link to the package by right clicking the orange Download button, click “copy link address”, and then paste it after the wget -c command: wget -c http://22.214.171.124/download/3.5.0/Linux/FE/nxserver_3.5.0-11_amd64.deb
Then install the packages with the dpkg -i command (if on Ubuntu or Debian). For example: sudo dpkg -i nxserver_3.5.0-11_amd64.deb
3. Configure the NX server
While the default configuration may work, there are a few things to check up on. The configuration files for NX are in /usr/NX/etc/ , and you’ll likely only need to edit /usr/NX/etc/server.cfg. The configuration file is filled with relatively easy to understand informative comments about available options so you shouldn’t have a too hard time with it. You can use nano command line text editor to edit this file: sudo nano /usr/NX/etc/server.cfg
If you just want to be able to log in with your SSH credentials then make sure EnableUserDB = “0″ and EnablePasswordDB = “0″ are set (both disabled).
Also make sure you set your SSHDAuthServer, which is to say the hostname of the server used for NX SSH authentication. If your server is at example.com, for example, then you would set SSHDAuthServer = “example.com”. Finally check that your SSHDPort and SSHDAuthPort are both set correctly. Typically this will be port 22 if that’s what you use to SSH into your server. All of these settings should be uncommented (the # character in front of them removed) in order to apply with a non-default option.
Once you’re done editing server.cfg don’t forget to save it (Ctrl-X, then “y”, and return key, in nano).
4. Start the NX server
To start the NX server just run sudo /etc/init.d/nxserver start. If it’s already running change “start” to “restart”. You should restart the NX server after every time you edit the configuration (as above).
5. Configure the NX client on your computer
This should be fairly straightforward to do with the NX Connection Wizard. You just have to name your session, enter the correct hostname and SSH port, select Unix and the desired Desktop environment (if unsure go with Custom). Don’t worry too much though as you can change and tweak your configuration with the NX client itself (separate program from the NX Connection Wizard). The wizard is just supposed to be helpful.
You will likely want to tweak your Desktop settings if you chose “Custom” (rather than KDE, GNOME etc), depending on what you’ve got installed on your server. For example, I have Xfce desktop environment on mine so I set the NX client to run “startxfce &” when it connects.
I also have it set to create a “New virtual desktop” when connecting as opposed to “Floating window”. Either option is fine, depending on your needs. If you just want a specific graphical program to run, and it doesn’t have many windows, then a “Floating window” option should be preferable. If you want to run a full desktop environment (like KDE, GNOME, Xfce, LXDE and so on) then “New virtual desktop” is the logical option.
Another thing you’ll probably want to tweak are the Display settings. If you chose to use a “new virtual desktop” you can set its display size. You can choose from one of the predefined resolutions, available area (a maximized window), full screen, or custom (which allows you to set your own resolution). You can also set up additional custom settings regarding image compression and rendering in case you wish to try out multiple things to optimize your performance. I found defaults to be just fine.
When you’re done configuring make sure to press the “Save” button to save, and then the Ok button to dismiss the dialog.
Once all of this is set up, all that’s left to do is to connect. Depending on how you configured the client, and if you configured the server correctly, you should see either a Terminal (xterm by default), a specific application you set to start on login, or a desktop environment (like Xfce in my example).
That’s about it. You should find the performance pretty impressive depending on the resources on your server machine. The main bottleneck is your network speed and latency. I’m actually finding that running the remote desktop environment over the network like this to be speedier than virtualizing an operating system on my own desktop machine, but then again my VPS, with its 8-core Xeon CPU, beats my dual core Core 2 Duo desktop by a long shot.