Configure remote desktop using RDP on AL2027
AL2027 Preview
AL2027 is currently available for preview. It is intended for evaluation and testing only and is not recommended for production workloads.
AL2027 does not include the TigerVNC server that was available in AL2023. To remotely access the graphical desktop, use the Remote Desktop Protocol (RDP) provided by GNOME Remote Desktop. GNOME Remote Desktop is included with the GNOME desktop environment. The following procedures configure the system-level RDP service. When you finish, you can connect to the graphical login screen and log in with your user account.
Contents
Prerequisites
-
You use SSH port forwarding to access the RDP server. For more information about setting up your key pair, see Connect to your Linux instance using SSH in the Amazon EC2 User Guide.
-
The following procedure does not guide you through the process of installing an RDP client. You must have an RDP client installed on your local machine to be able to connect to and interact with the desktop environment.
Step 1: Install the desktop environment
-
Connect to your instance using SSH.
-
Install the GNOME desktop environment and the
systemd-pampackage. TheDesktopgroup includes GNOME Remote Desktop, which provides the RDP service. Thesystemd-pampackage is required for the graphical login session.sudo dnf group install "Desktop"sudo dnf install systemd-pam
Step 2: Create a TLS certificate
RDP connections are always encrypted with TLS, so GNOME Remote Desktop requires a
server certificate before the service can be enabled. The following steps create a
self-signed certificate owned by the gnome-remote-desktop service user. If
you want to use a certificate issued by a certificate authority instead, see the
optional section at the end of this topic.
-
Create the directory that holds the certificate and key.
sudo -u gnome-remote-desktop mkdir -p ~gnome-remote-desktop/.local/share/gnome-remote-desktop -
Generate a self-signed certificate and private key.
sudo -u gnome-remote-desktop openssl req -new -newkey rsa:4096 -days 720 -nodes -x509 \ -subj "/C=US/ST=NONE/L=NONE/O=GNOME/CN=gnome.org" \ -out ~gnome-remote-desktop/.local/share/gnome-remote-desktop/tls.crt \ -keyout ~gnome-remote-desktop/.local/share/gnome-remote-desktop/tls.keyNote
This example command generates a certificate that is valid for 720 days, after which you need to regenerate it. Consider changing the parameters to suit your environment.
Note
The certificate and key must be readable by the
gnome-remote-desktopservice user, which is why the files are created withsudo -u gnome-remote-desktop.
Step 3: Configure and enable the RDP service
-
Configure the RDP service to use the certificate and key.
sudo grdctl --system rdp set-tls-key ~gnome-remote-desktop/.local/share/gnome-remote-desktop/tls.keysudo grdctl --system rdp set-tls-cert ~gnome-remote-desktop/.local/share/gnome-remote-desktop/tls.crt -
Set the RDP credentials. You are prompted for a username and password.
sudo grdctl --system rdp set-credentialsNote
These credentials are used only to authenticate the RDP connection. They are not connected to a system user account, and the username does not need to match one. After the RDP connection is established, you log in to the desktop with your system user account at the graphical login screen.
-
Make sure the system user account you use at the graphical login screen has a password you can enter. For a local account that does not have a password, set one as shown. If the account already has a password, skip this step and use its existing credentials.
sudo passwd <username>Note
Replace
<username>with the system user account you log in with (for example,ec2-user). -
Enable the RDP service.
sudo grdctl --system rdp enableNote
On instances without a TPM device,
grdctlprintsInit TPM credentials failed because No TPM device found, using GKeyFile as fallback. This message is expected. The credentials are stored in a file that is readable only by the service user. -
Start the graphical login screen.
sudo systemctl start gdm.serviceAfter performing this step, you can create the SSH tunnel from your local machine and connect using your RDP client.
Step 4: Connect using an RDP client
The RDP server listens on TCP port 3389. You can expose this port directly through your security group. Instead, these steps use SSH tunneling, which is more secure. The SSH tunnel authenticates the instance and encrypts the connection between your local machine and the EC2 instance, so port 3389 is never exposed to the network. For more information about security groups, see Change the security groups for your Amazon EC2 instance in the Amazon EC2 User Guide.
-
Create an SSH tunnel from your local machine.
$ssh -i <keypair> -L <local-port>:localhost:3389 ec2-user@<address>Note
Replace
<keypair>with the path to your SSH key and<address>with your instance's public IP or DNS name. Replace<local-port>with any available port on your local machine (for example,5000). Don't change the remote port3389; that is the port the RDP server listens on. On some local machines, port3389is already in use, so choosing a different local port avoids conflicts. -
Use your RDP client to connect to
localhost:<local-port>(for example,localhost:5000) with the RDP credentials you configured in the previous step.Note
Your RDP client might warn that the server certificate can't be verified. You can safely accept the warning here, because the SSH tunnel already authenticates the instance and encrypts the connection. Don't ignore certificate warnings when connecting directly over the network.
-
Log in with your system user account at the graphical login screen to start the desktop session.
Important
Keep the SSH tunnel open while using RDP. If the SSH tunnel isn't open, your RDP client can't view or interact with the desktop environment.
(Optional) Start the service at boot
If you plan to use RDP regularly, configure the instance to boot into the graphical target so that the login screen and the RDP service start automatically when your instance boots.
-
To start the login screen and RDP service automatically at boot, set the default boot target.
sudo systemctl set-default graphical.targetAfter performing this step, you will no longer need to start
gdm.serviceevery time you reboot your instance.
(Optional) Disable RDP access
If you no longer need remote desktop access, disable the RDP service so the instance stops listening for connections.
-
Disable the RDP service.
sudo grdctl --system rdp disable -
If you changed the default boot target earlier, restore it to the multi-user (non-graphical) target.
sudo systemctl set-default multi-user.target
(Optional) Use your own TLS certificate
Instead of the self-signed certificate from Step 2, you can use a certificate issued
by a certificate authority that your clients trust. Register it with the same
grdctl --system rdp set-tls-key and set-tls-cert commands from Step
3. With this, your RDP client can verify the server identity, so you can connect
directly to port 3389 without an SSH tunnel. If you connect directly, restrict inbound
access to port 3389 in your security group to known source IP addresses. For
instructions, see Change the security
groups for your Amazon EC2 instance in the Amazon EC2 User Guide.
Related topics
For more information about the graphical desktop environment, see the following documentation:
-
What Is Amazon DCV? in the Amazon DCV Administrator Guide