In this small project, we had to create a preconfigured Linux machine with a graphical interface in AWS, reachable over Remote Desktop (RDP), from which another identical machine could be launched at any time. The solution was an EC2 instance with XRDP, and an AMI template made from it.
Starting point
The task was an Ubuntu-based desktop environment with the required applications preinstalled, which could also be reached from Windows with the built-in Remote Desktop Connection program. Since several similar machines might be needed, it was important that a new instance would start from a template within minutes, not through a manual installation.
Solution
The base EC2 instance
We launched an EC2 instance from the official Ubuntu 20.04 LTS AMI on AWS. A desktop environment needs more memory than a traditional server, so the instance type has to be chosen accordingly.
XRDP and the desktop environment
We installed the full Ubuntu Desktop package and the XRDP server on the instance:
sudo apt install ubuntu-desktop xrdp
sudo systemctl enable --now xrdp
Two small things that tend to trip up the first RDP connection:
- XRDP has to read the system’s TLS key, so its user must be added to the
ssl-certgroup:sudo adduser xrdp ssl-cert. - On EC2, the default
ubuntuuser has no password, because it logs in with an SSH key. RDP needs a password, so either give it one or, better, create a separate user.
Secure access
It’s not a good idea to open the RDP port (3389) to the whole internet. There are two good options: allow it in the security group only from the users’ fixed IP addresses, or don’t open the port at all and reach it through AWS Systems Manager port forwarding:
aws ssm start-session --target i-0123456789abcdef0 \
--document-name AWS-StartPortForwardingSession \
--parameters '{"portNumber":["3389"],"localPortNumber":["13389"]}'
Then you connect to localhost:13389 with the Remote Desktop Connection program. Setting up Session Manager is covered in a separate article: AWS SSM: no more need for SSH.
Applications and the AMI template
Once the RDP connection worked properly, we installed the required applications and then made an AMI template from the instance. Before creating the template, it’s worth cleaning up the machine (temporary files, command history), because everything on it is carried over to every new instance. The SSH host keys don’t have to be deleted by hand: in Ubuntu’s cloud images, cloud-init generates new ones on each new instance’s first boot.
In the console, the AMI is created from the instance’s Actions menu (“Image and templates → Create image”), and from the command line like this (by default, the command reboots the instance so that the disk image is consistent):
aws ec2 create-image --instance-id i-0123456789abcdef0 --name "ubuntu-rdp-desktop-v1"
In a launch template built on the AMI, the instance type, network and security group can also be preset, so a new machine really does start with a single click.
Result
A preconfigured Linux desktop machine reachable over RDP, from which another one can be launched at any time, within minutes, using the AMI template, with no manual installation.
Looking back from 2026
Standard support for Ubuntu 20.04 LTS ended on 31 May 2025, and since then only Ubuntu Pro (ESM) provides security updates for it. Today we would build on 24.04 LTS, and since there is no direct upgrade path from 20.04 to 24.04, it’s better to rebuild existing machines from a new template rather than upgrade them in place.
Instead of building the template by hand, today we would also automate the AMI build (for example with EC2 Image Builder or Packer), so that after the applications are updated, a new, versioned template is created automatically. We write more about cloud work like this on the Cloud and DevOps page.