I’ve always been looking for a way in NX/FreeNX to be able to authenticate using mechanisms other than username and password, like SSH private/public keys or Kerberos. Turns out that it is possible 🙂
Someone pointed me to the FreeNX 0.7.3 announcement that contains the following excerpt:
Usermode and SUID Wrapper
We are now very close to login directly with users and I also heard of a C program, which can be seamlessly put between nxclient and nxssh. So with client support we now have three alternatives:
1. Login as user via ssh and connect to server with ssh command on server again.
2. Login as user and use usermode to save all sessions locally for each user.
3. Use a SUID nx (not root!) wrapper to startup a new "trusted" session.
One is error prone, two is good, but looses the central structure, three is best of both worlds and with being suid nx also has the most advantages, however not the dreaded public key problems.
_Yes_, this means if you use the suid wrapper, you still need the nx user, but you can remove the public keys and it'll still work.
The SUID wrapper is a part from the work of the redesign and thanks goes to Alistair Riddoch from Google here.
By default, NoMachine’s NX nxserver requires nxclient to login via SSH into the remote machine as user
nxserver is defined as the login shell, it is run by the
sshd daemon. From there on, there is a dialogue between nxclient and nxserver where nxclient supplies the user credentials (username and password that were specified in the nxclient configuration). There is, in fact, a second authentication that is performed via another SSH session to 127.0.0.1 using nxclient’s supplied credentials. If this second authentication succeeds, the NX session is activated and accessible from the NX client.
This works well for remote servers that are shared by multiple users, as the
nx user and its centralized approach makes it very easy to see how many sessions are currently running (or suspended), terminate them, etc. However, for machines that are not shared by multiple users, or in those cases where authentication mechanisms other than username and password are required, this model does not work very well.
This is where FreeNX’s usermode enters the scene. Basically, what it means, is that authentication to nxserver does no longer happen as the
nx user but as the end-user himself. Now, the number of SSH sessions is reduced to one that authenticates the user directly by means of SSH’s built-in authentication capabilities, and where nxserver is run under the end-user credentials instead of the
nx user. This, obviously, kills the centralized approach originally envisioned by NoMachine, since now all the control and session files can’t be stored easily and securely in a central location but are now stored in the user’s home directory. But I think the upsides of the usermode support outdo the lack of centralized management. At least in my case, I don’t need centralized management since it’s me who manages all my boxes and logs into them.
How to install and configure FreeNX to support usermode
Next I describe what I had to do, both on the remote machine and also on the client, to get a working FreeNX environment that supports usermode. Other modes are also supported, like legacy nx-based, SUID and others.
Download NX4U tarball from BerliOS and extract it
$ wget http://download.berlios.de/freenx/NX4U.tar.gz $ sudo tar -C /opt -zxf NX4U.tar.gz
NOTE: The NX4U tarball that I used can also be downloaded from this Web site here.
NOTE: The NX4U set and the nxssh wrapper are smart enough so that you can also extract the NX4U tarball in other locations. Looking at the source code for the nxssh wrapper —
nxssh-4US.c — nxssh wrapper uses the following PATH to locate the nxserver binary:
#define NXSERVER_PATH "~/bin: ~/NX4U/: /usr/NX/bin: /opt/NX/bin: /opt/NX4U/bin: /usr/NX4U/bin: /usr/local/NX4U/bin: /usr/lib/nx/bin"
Compile the nxssh wrapper
First, download the source code from the SVN repository:
$ svn checkout https://email@example.com/svnroot/repos/freenx/trunk
NOTE: I saved a copy of the SVN repository that I used. The tarball is available in this Web site here.
Build the nxssh wrapper for Mac OS X. nxssh is a simple C program that currently compiles for me with no problems on Linux and Mac OS X:
$ cd trunk/freenx-utils/nxpublickey/ $ make nxssh
NOTE: The Makefile also has a target named nxssh.exe to compile the wrapper for Windows.
Now, let’s rename NoMachine’s nxssh binary to mxssh (the nxssh wrapper expects NoMachine’s nxssh binary to be renamed to mxssh), then install the nxssh wrapper:
$ sudo bash # mv /usr/NX/bin/nxssh /usr/NX/bin/mxssh # install -m755 nxssh /usr/NX/bin/nxssh # ^D
What looks like a bug in NoMachine’s nxssh, will cause authentication requests using public key to fail with a
"percent_expand: NULL replacement" error unless
.ssh/config is modified to explicitly state the location of the public key. For example:
Host my.host.org IdentityFile ~/.ssh/id_dsa
In order to use usermode authentication, make sure to prepend the hostname with the @ (at) sign:
Also, make sure the username has the @ (at) sign prepended plus @U (at U) appended. These non-standard forms are parsed by the nxssh wrapper and enable usermode authentication (or other authentications like SUID):
For more information about possible syntaxes, take a look at
freenx-utils/nxpublickey/nxssh-wrapper (the shell script implementation of the