Article: Setting up NX server (part II: NoMachine NX)

To install NoMachine NX Free Edition, you’d normally download the required packages (nxserver, nxnode and nxclient) for your distro (.rpm, .deb, .tgz) and system architecture (i386 or x86_64) from the NoMachine website:** NX Free Edition for Linux**](http://www.nomachine.com/download-package.php?Prod_Id=3772), and install them as you would install any package on your distro - under openSUSE, with zypper in or rpm -i (which also works on all rpm based Linux).

nomachine-setup can take care of this, by querying the latest available version on the website and comparing it with the installed version (if this package is installed), downloading the files and installing them. It can be used for both purposes, installing and updating NoMachine NX Free Edition. If a package is present in the rpm cache (under openSUSE /var/cache/zypper/RPMS), it won’t be downloaded again. If the NoMachine site doesn’t respond (as sometimes happened lately), and a package is found is the rpm cache, it will be considered as the latest available version. It’s unlikely to be newer than the one already installed - although nomachine-setup downloads the files into the rpm cache directly and you may copy files from there to /var/cache/zypper/RPMS on another machine. If no (newer) package can be found, no installation or update will occur.

nomachine-setup](http://www.unixversal.com/linux/openSUSE/nomachine-setup) is a bash script included in the FreeNX package available in my repo (see part I of this article on how to install it) and installed in /usr/bin. However you won’t want to install FreeNX if you don’t need it, so you can just download nomachine-setup, save it in a directory in your path and make the script exectutable.


# su -l
# cd /usr/bin
# wget [http://www.unixversal.com/linux/openSUSE/nomachine-setup](http://www.unixversal.com/linux/openSUSE/nomachine-setup)
# chmod 755 nomachine-setup

The following command installs NoMachine NX server Free Edition:

# nomachine-setup --server

The client gets installed automatically with the server. The option** --server** (-s) is enabled by default. Thus the command above is the same as:

# nomachine-setup

To install the client only - as discussed earlier in part I of this article - use this command:

# nomachine-setup --client

nomachine-setup also applies some changes to /usr/NX/etc/node.cfg and /usr/NX/etc/server.cfg. It corrects wrong paths, defines some defaults and changes the base DISPLAY number from 1000 to 2000 to differentiate it from FreeNX - so the client can check the DISPLAY environment variable to find out if the server is running FreeNX or NoMachine NX. Once nomachine-setup has completed the installation, the NX server will start and listen on port 22, using the default NoMachine DSA key pair. Linux, Windows and Mac OS X clients can connect with the NoMachine client without having to import keys.

If the NoMachine NX server and/or client is already installed, the commands above can be used to update the packages to the latest version.

Creating a new DSA key pair

nomachine-setup follows NoMachine defaults by using the generic NoMachine DSA key pair - unlike freenx-setup which creates a DSA key pair by default. As already mentioned, the latter approach is safer if clients connect to your NX server from the Internet. To have the NX server use your own DSA key pair and let the setup create one, run nomachine-setup with the option -k (–keys). This option does the opposite of the -n --nokeys option of freenx-setup (see part I).

# nomachine-setup --keys

You can also use this command anytime to create a new DSA key pair if NoMachine server is already installed.

A session configuration file (.nxs) will be written in /usr/share/NX. You should copy this file to ~/.nx/config on the client or import the private key /usr/share/NX/keys/default.id_dsa.key in the session configuration file.

Running NoMachine on an alternate port.

Like freenx-setup, nomachine-setup has an option to set up NoMachine server to listen on an alternate ssh port -p (–port). You may refer to the section Running FreeNX on an alternate ssh port in part I, since it works similarly (enabling and opening the alternate port, etc). To setup NoMachine to listen on SSH port 9123, use the following command:

# nomachine-setup -p 9123

9123 is also the default alternate port for NoMachine server. This is an arbitrary choice. You can change it by assigning another value to the variable NXPort, defined at the top of the script. If FreeNX is already installed, this alternate ssh port will be automatically used for the NoMachine server, unless you also specify the option **-n **( **–nofreenx **) in nomachine-setup.

Changing settings without checking for updates.

Normally, everytime you run nomachine-setup, whether to install or update NoMachine software, create an new DSA key pair or set up an alternate ssh port, the script connects to NoMachine website, parses the list of download URLS and check these URLS one by one. As the site happens occasionally to be down, it might take a while to time out ($curlTimeout * number of urls to check) before applying your changes. The option -q (–quick) will skip this step and drastically speed up the process. Use this option if all you want is to create DSA keys or change the ssh port the server should listen on.

Examples:

  • changing the ssh port:
# nomachine-setup -q -p 9124
  • changing the DSA key pair:
# nomachine-setup -q -k

Installing packages from RPM cache only.

The NoMachine website sometimes takes so long to respond to curl and wget that I had to add an option -o (–offline) to test my script. With this option, nomachine-setup won’t try to query the NoMachine website nor download files from there. It will take the latest version of nxclient, nxnode and nxserver found in /var/cache/zypper/RPMS, copy the files to /tmp and install from this directory - zypper can not install from RPM cache directly, because it can not copy the file onto itself. zypper has no way to know if the packages present in rpm cache are the latest release (there isn’t a NoMachine repo). If more than one version is found, it will install the higher one. If the packages are not there, the script will abort with an error message. This option can be useful if you already have the packages. If you want to install NoMachine NX on another openSUSE system, simply copy the rpms to /var/cache/zypper/RPMS on this machine and run:

# nomachine-setup -o

It might save you a couple minutes.

Installing and running FreeNX and NoMachine in parallel.

While nomachine-setup provides a fast and convenient way to install NoMachine server alone, the script becomes particularly helpful when FreeNX is already installed and you want to run both NX servers. I won’t answer the question “why” you would do that, just show you “how” to achieve it. When both NX servers are installed and running, clients can open a FreeNX or NoMachine session by just changing the ssh port - you might create separate session configuration files, but you don’t need to.

The command to install NoMachine NX server in parallel with FreeNX is simple and straightforward. Just type:

# nomachine-setup --server

Or just:

# nomachine-setup

Optionally, you can specify a ssh port with the option** -p**. Otherwise nomachine-setup will take 9123 - or the value of NXPort in the script.

This assumes that FreeNX is installed and configured properly (for example with freenx-setup). nomachine-setup will also apply the necessary changes to FreeNX /etc/nxserver/node.conf, so that incoming NX connection on port 9123 will be redirected to the NoMachine server. The FreeNX DSA key pair will be used for authentication. To open a NoMachine rather than a FreeNX session, simply change the port in the session configuration file on the client. Keep in mind that you can only have two simultaneous client connections with NoMachine Free Edition, while the number of client with FreeNX is effectively unlimited - more precisely it is defined in the variable SESSION_LIMIT in /etc/nxserver/node.conf and the default is 200.

If FreeNX is installed and you don’t want it to be the main NX server, you can use option -n (–nofreenx). In this case, NX connection will go to the NX server directly, the nx user home directory and shell will point to NoMachine, and FreeNX will be disabled. FreeNX can redirect connections on a specific port to NoMachine, but it is not possible in the other direction. Thus, if you use both, FreeNX has to be the main server.

If you plan to install both, install FreeNX first on an alternate port, then install NoMachine server. If you don’t specify an alternate port, it will take 9123.

Deinstalling NoMachine without breaking FreeNX

If you deinstall NoMachine packages with YaST or zypper, it will execute the post-uninstall scriptlet included in the rpm, which at the end deletes the nx user. As a consequence, you won’t be able to login in FreeNX anymore, becauses it needs the nx user as well. To deinstall NoMachine without breaking FreeNX, use nomachine-setup with the option **-d **( –deinstall). It will remove the packages while skipping the %post and %postun scriptlets.

nomachine-setup -d

This is equivalent to the following command:

rpm -v -e --noscripts nxserver nxnode

If FreeNX is not installed, option** -d** will run zypper rm instead and the nx user will be deleted.

If you inadvertently deinstalled NoMachine with zypper, you can use freenx-setup with option** -U (–nxuser**) to restore the nx user. The following command restores the nx user and exits:

freenx-setup -U

Notice that it is a capital “U”.

Deinstalling with nomachine-setup -d also removes the directories /usr/NX/etc, /usr/NX/home and /usr/NX/var. This is straightforward, but reinstalling NoMachine might fail if these directories exist, are not empty an the UID of the nx user has changed - which is necessary if FreeNX is also installed. If you want to keep these directories and their content, you can comment out the variable PURGE_CONFIG in the script. I wouldn’t recommend it if you intend to reinstall NoMachine at a later point.

**Summary: **

To install FreeNX AND NoMachine NX server and use them both, here’s all you have to type:

$ su -l
# zypper ar http://download.opensuse.org/repositories/home:/please_try_again/openSUSE_12.1/  PTA
# zypper --gpg-auto-import-keys refresh -r PTA
# zypper in FreeNX
# freenx-setup -p 9122
# nomachine-setup -p 9123

Then copy the file /var/lib/nxserver/home/SERVER.nxs (SERVER being the name of the NX server) in ~/nx/config on the client.

Caveats.

If you want to run both FreeNX and NoMachine NX servers, have to install FreeNX first - as it would require more scripting to do it the other way around.

nomachine-setup is intended to work in other distros, but I have been testing it only on openSUSE so far.