Ubuntu 16.04 Xrdp Server Setup

This article is written for configuring an Ubuntu 16.04 server to be used with a graphical user interface connected via port 3389.

Create EC2 Instance

Create an Ubuntu 16.04 Server via the AWS EC2 console. I used AMI: ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20180627 (ami-759bc50a). Ensure you have access to the instance by having a key pair readily accessible.

Configure ssh-agent

Configure your ssh-agent to allow you to connect to your instance. I personally use gitbash on windows but prefer to use pretty much any linux distribution as these features are typically built into the Operating System. Ensure you have your ssh-agent running, you can verify it is running like so:


eval $(ssh-agent)

Eval concatenates together arguments and makes them into a single command, which is then read and executed, and its exit status returned as the exit status of eval. The reason eval is used is to create a new child process which allows the ssh-agent to modify the environment variables it needs to run properly. Just to add although not very important for configuring Ubuntu mate and Xrdp it is important to understand commands you run on your linux instances. To prove that the command above has different environment variables I show from a virt of mine the different environment variables of both processes.


mike@phobos:~$ ps -ef | grep ssh-agent
mike      2709  1869  0 14:03 ?        00:00:00 ssh-agent
mike@phobos:~$ echo $$  # Get the process ID of the terminal
2681

Finally you can see for yourself the different if you run the same command below:


mike@phobos:~$ cat /proc/1869/environ | tr ':' '\n'
mike@phobos:~$ cat /proc/2681/environ | tr ':' '\n'

Lastly, just add your keys pem file to your ssh-agent so we don't have to do ssh -i <pemFile> every single time.


ssh-add ~/.ssh/<yourPem>
ssh-add -l

Connect to Instance

Connect to your EC2 instance using ssh


mike@phobos:~$ ssh ubuntu@54.175.172.253

Configure Ubuntu Mate

Let's install ubuntu mate and xrdp real quick. See the command line commands below:


ubuntu@ip-172-31-56-39:~$ sudo apt install tasksel -y
ubuntu@ip-172-31-56-39:~$ sudo apt update -y
ubuntu@ip-172-31-56-39:~$ sudo tasksel install ubuntu-mate-desktop
ubuntu@ip-172-31-56-39:~$ sudo apt upgrade -y

Configure Xrdp

Install xrdp and verify it is working. This doesn't set up server verification with SSL certificates so you are assuming some risk that you are connecting to the endpoint you are expecting.


ubuntu@ip-172-31-56-39:~$ sudo apt install xrdp -y
ubuntu@ip-172-31-56-39:~$ sudo service xrdp status

Create User for Xrpd

Let's create a user so we can use password authentication to connect to our xrdp session. You can add a password to the ubuntu user or my preference is to create a new user and add a password to that user.


sudo adduser USERNAME
sudo adduser USERNAME sudo
sudo su USERNAME
cd ~
echo mate-session >~/.xsession
sudo service xrdp restart

Connect via Xrdp

Verify that your security groups allows Remote Desktop Protocol (RDP) port 3389. Open up windows remote desktop and connect to the ip address and type in the user name and password and that is it! You could see it look like the screen shot below:

ubuntumate