How to set up key based authentication with SSH protocol
This article applies to NoMachine v. 4 or later.
Support for key-based authentication with the SSH protocol requires the public SSH key be added on the server side, in the user's home, to grant access. When you connect to the server you will have to insert the private key in the NoMachine User Interface (UI). Key types supported are RSA, DSA, ECDSA and ED25519.
Key-based authentication with SSH protocol is not available with the free edition of NoMachine.
What you need to have done first
You have already generated an SSH key pair, for example by using the ssh-keygen tool on a Linux host, e.g.:
ssh-keygen -f my_key
It will generate two keys, the private one (my_key) and the public one (my_key.pub).
IMPORTANT
1) You have already generated an SSH key pair, for example by using the ssh-keygen tool on a Linux host.
Be sure that the keys are in OpenSSH format.
If you're using a NoMachine version older than v. 6.9.2 and openssh version 7.8p1-1 or later, specify to generate the key in the old format:
ssh-keygen -m PEM -t rsa -b 4096
NoMachine supports the new OpenSSH format introduced by openssh version 7.8p1-1 since v. 6.9.2.
2) If you have generated the SSH key pair on Windows, for example by using PuTTYgen (https://www.puttygen.com), be sure it's in OpenSSH format or convert it. To do that choose the key file in the PuTTYgen main window. Then go to Conversions->Export OpenSSH key to export your private key and save it.
3) 3) NoMachine on Windows cannot connect to OpenSSH server v8.8 or later by RSA keys, see https://kb.nomachine.com/TR10V11235 for more details and a possible workaround.
Add the public SSH key on the server
Content of the public key have to be added to the authorized keys file on the remote computer.
The authorized keys file, usually 'authorized_keys' (or 'authorized_keys2' on old systems), is placed in the user's home directory: <user's home>/.ssh/authorized_keys.
On Linux and Mac hosts, check the configuration of SSHD (sshd_config) to verify path and name to the authorized keys file. When both 'authorized_keys' and 'authorized_keys2' are valid, 'authorized_keys' is preferable.
On Windows, NoMachine ships its own SSH server (nxsshd) which uses the authorized_keys file in the %USERPROFILE%/.ssh directory.
On the remote computer, create the authorized_keys file in the appropriate place, if it doesn't exist yet.
Then, append your SSH public key at the end of the authorized keys file and save changes.
For example on Linux, to add the public key to the authorized_keys file of user nxtest01 upload the my_key.pub file on the remote host and execute from a console :
cat my_key.pub >> /home/nxtest01/.ssh/authorized_keys
Use the private SSH key when connecting with your client
On the user's computer:
1. Launch the NoMachine User Interface from Programs menu or Applications and right click on a connection. Choose 'Edit connection' to access connection settings.
2. In the 'Address' panel sure that SSH is the selected protocol in the drop-down menu.
3. In the 'Configuration' panel select 'Use key-based authentication with a key you provide'
4. Click on Modify and provide path to your private SSH key (e.g. my_key).
5. Connect to the server.
The client will prompt you for username and passphrase. If your SSH key doesn't have a passhprase, leave this field empty.
