Accessing an Ubuntu desktop on Amazon's Elastic Compute Cloud via NoMachine
We will show you in this article how to create your Amazon EC2 instance running Ubuntu 14.04 or 16.04, install the desktop environment (Amazon EC2 Linux instances don't come with a GUI by default) and install NoMachine to provide remote desktop access to your VM.
We're going to install NoMachine (free version) on a virtual Linux host, and then access the desktop of this virtualized Linux OS. You can of course install any of the enterprise-oriented products as well.
Specific notes for Ubuntu 14.04 or 16.04 are evidenced, otherwise steps below apply to both versions.
1) Log-in to Amazon AWS
Go to the www.aws.amazon.com website and from the menu 'My Account' choose AWS Management Console. Log in or create an account.
2) Choose the Amazon Machine Image (AMI)
Once logged in, you'll see the EC2 Dashboard. Choose 'Instances' in the dashboard menu, then launch the instance.
Select "Free tier only" and choose Community AMI. Search for 'Ubuntu 14.04' or 'Ubuntu 16.04' in the search box and select any of the images. We suggest to select a 64bit architecture.
3) Choose the HW for your VM
At Step 2 of the Amazon Wizard you will be asked to 'Choose any Instance Type'. This basically lets you change the hardware for your VM. Free tier options will be highlighted for you if they are available.
4) Set-up the "Security Groups" policies
Follow the Amazon Wizard till step 6. Update the security group rules to allow access from known IP addresses only and open port 4000 for NoMachine connections by NX protocol:
- Add rule for the "Custom TCP Rule" type, protocol TCP and write 4000 in the Port Range field.
- in "Source" select Anywhere or Custom IP.
Leaving 0.0.0.0/0 means that any computer can connect to your VM over the Internet. If you want to allow a specific set of IP addresses (for users who will be accessing from a fixed IP for example), insert them here.
Click on 'Review and Launch' to proceed with the next step of the wizard.
5) Set-up the SSH key pair
The AWS Dashboard has 'Type' SSH set by default for Linux. This is to allow you to get secure access to the VM so that you can start to install and set up your VM. Once you've installed NoMachine, you'll be accessing the VM using NX protocol.
In Step 7 of the AWS procedure, a new window will appear where you must create or choose an existing key pair. This is a necessary step in the set-up of your VM. Connecting to your VM via SSH will only be possible with this key pair in place.
- Select 'Create a new key pair' and enter a name in the 'Key pair name' field, for example "MyKey"
- Click 'Download Key Pair' to save the private key to your computer.
TIP: Remember where you saved this key. You will need it later to connect by NoMachine and key-based authentication.
6) Launch the EC2 instance
Launch the instance. You will be able to see it in the 'Instances' panel of the AWS Dashboard.
Now you can give a name to your VM. Your VM is ready when you see a green dot in the Instance State column.
7) Connect by SSH to your instance
A Virtual Instance on AWS is created without a GUI, we will then need to install a graphical environment. To do that, we firtstly need to connect by SSH.
- Click the Connect button: a window will appear with the details of your VM.
TIP: Make a note of this information. You will need it to connect to your VM via SSH. This information is also required to connect via NoMachine.
In our example we have:
username, ec2-user
VM hostname, ec2-54.194.185.70.eu-west-1.compute.amazonaws.com
VM public IP, 54.194.185.70.
- Select the 'A standalone SSH client' radio button.
Now open a terminal on your local computer and move to the folder where the key you downloaded earlier is saved.
- Change your private key permissions:
chmod 400 MyKey.pem
- In the terminal, enter the information you noted earlier to connect by SSH to your VM, e.g.,
ssh -i "MyKey.pem" ec2-user@ec2-54.194.185.70.eu-west-1.compute.amazonaws.com
- Press Enter. Accept the RSA key fingerprint when prompted. You'll now be securely connected via SSH to the remote VM.
8) Configure the Ubuntu VM
In a terminal on your local PC from where you are connected by SSH to your VM, run the following commands to list and fetch new versions of packages and their dependencies:
sudo apt-get update
sudo apt-get upgrade
NOTE for Ubuntu 14.0.4 only: in the Ubuntu package configuration window choose: 'keep the local version currently installed' and click on 'Ok'.
9) Install a desktop environment on Ubuntu
We suggest to use a lightweight desktop like Xfce.
In the same terminal connected from your PC to the VM, execute:
sudo apt-get install xfce4
10) Install NoMachine on your VM
Now that the Ubuntu desktop is prepared, it's ready for NoMachine to be installed.
Download the NoMachine package suitable for your VM from our website https://www.nomachine.com/download and save it on your computer.
Then transfer the NoMachine installation package to the VM by using scp. In our example, we executed in a terminal on the local computer:
scp -i "MyKey.pem" /home/nomachine/Pkg/nomachine_5.1.54_1_amd64.deb ec2-username@ec2-54.194.185.70.eu-west-1.compute.amazonaws.com:~
Once the upload is complete, from the same terminal connect again by SSH to your VM:
ssh -i "MyKey.pem" c2-user@ec2-54.194.185.70.eu-west-1.compute.amazonaws.com
and install the NoMachine package by running in the terminal:
sudo dpkg -i nomachine_5.1.54_1_amd64.deb
Remember the SSH key you downloaded earlier? When Amazon created this private key, it also generated a public key on the server-side. This public key must be added to the NoMachine user's home to grant access via key-based authentication.
In the same terminal from before, browse to the user's home directory. Check that /.nx/config directory exists. If it doesn't exist, create it.
Copy the SSH key to the config directory and rename it to authorized.crt:
cp -p .ssh/authorized_keys .nx/config/authorized.crt
11) Connect by NoMachine to your VM on Amazon EC2
If you haven't done so already, you need to install NoMachine on the computer or device you would like to connect from. Follow step by step the NoMachine wizard to create your first connection (it's the 'New' button).
When requested, enter the name of the host or its public IP that Amazon allocated for you when you created your VM and continue.
Choose 'Private key' as authentication method and browse to the folder where you downloaded Amazon's key and select it.
Complite all steps of the NoMachine wizard and save your session.
When connecting by NoMachine, you will be requested to provide your username: enter the Username which Amazon allocated you, in our example ec2-user.
References
A step-by-step tutorial to set-up a RHEL 6 Linux desktop on Amazon EC2 is available here: https://www.nomachine.com/accessing-your-remote-linux-desktop-on-amazon-elastic-compute-cloud-via-NoMachine .
Amazon's guide to get started with VM instances: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html
