The author selected the COVID-19 Relief Fund to receive a donation as part of the Write for DOnations program.
Remote Desktop Protocol (RDP) is a network protocol developed by Microsoft that allows users to remotely access and interact with the graphical user interface of a remote Windows server. RDP works on the client-server model, where an RDP client is installed on a local machine, and an RDP server is installed on the remote server.
RDP is widely used for Windows remote connections, but you can also access and interact with the graphical user interface of a remote Linux server by using a tool like xrdp, an open-source implementation of the RDP server.
In this tutorial, you will install and configure an RDP server using xrdp on a Ubuntu 22.04 server and access it using an RDP client from your local machine. You will understand how to establish access to a remote Linux server by configuring and using an RDP connection.
Deploy your frontend applications from GitHub using DigitalOcean App Platform. Let DigitalOcean focus on scaling your app.
To complete this tutorial, you will need:
One Ubuntu 22.04 server with a non-root user with sudo
privileges, a firewall, and at least 1GB of RAM, which you can set up by following the Ubuntu 22.04 initial server setup guide.
A local computer with an RDP client installed. A list of available RDP clients for different operating systems is provided below:
In this step, you will install and configure a desktop environment on your Ubuntu server. By default, an Ubuntu server comes with a terminal environment only. A desktop environment will need to be installed to access a user interface.
From the available options for Ubuntu, you will install the Xfce desktop environment. Xfce offers a lightweight, user-friendly desktop environment for Linux-based systems.
To begin, connect to your server using SSH and update the list of available packages using the following command:
- sudo apt update
Next, install the xfce
and xfce-goodies
packages on your server:
- sudo apt install xfce4 xfce4-goodies -y
You will be prompted to choose a display manager, which is a program that manages graphical login mechanisms and user sessions. You can select any option from the list of available display managers, but this tutorial will use gdm3
.
After installing the desktop environment, you will now install xrdp on your server.
xrdp is an open-source implementation of the RDP server that allows RDP connections for Linux-based servers. In this step, you will install the xrdp on your Ubuntu server.
To install xrdp, run the following command in the terminal:
- sudo apt install xrdp -y
After installing xrdp, verify the status of xrdp using systemctl
:
- sudo systemctl status xrdp
This command will show the status as active (running)
:
Output● xrdp.service - xrdp daemon
Loaded: loaded (/lib/systemd/system/xrdp.service; enabled; vendor preset: enabled)
Active: **active (running)** since Sun 2022-08-07 13:00:44 UTC; 26s ago
Docs: man:xrdp(8)
man:xrdp.ini(5)
Main PID: 17904 (xrdp)
Tasks: 1 (limit: 1131)
Memory: 1016.0K
CGroup: /system.slice/xrdp.service
└─17904 /usr/sbin/xrdp
If the status of xrdp is not running
, you may have to start the service manually with this command:
- sudo systemctl start xrdp
After executing the above command, verify the status again to ensure xrdp is in a running
state.
You have now installed xrdp on your server. Next, you will review the xrdp configuration to accept connections from remote clients.
In this step, you will review the default configuration of xrdp, which is stored under /etc/xrdp/xrdp.ini
, and add a configuration for an RDP connection. You will also update the firewall settings.
xrdp.ini
is the default configuration file to set up RDP connections to the xrdp server. The configuration file can be modified and customized to meet the RDP connection requirements.
Open the file in nano
text editor or any editor of your choice:
- sudo nano /etc/xrdp/xrdp.ini
The configuration file contains different sections:
[Xorg]
and [XVnc]
. There is no [Sessions types]
heading in the file; instead, it is written as a comment.In the configuration file, navigate to the Session types
section. You will find multiple supported session types and their parameters listed:
Output...
;
; Session types
;
; Some session types such as Xorg, X11rdp, and Xvnc start a display server.
; Startup command-line parameters for the display server are configured
; in sesman.ini. See and configure also sesman.ini.
[Xorg]
name=Xorg
lib=libxup.so
username=ask
password=ask
ip=127.0.0.1
port=-1
code=20
[Xvnc]
name=Xvnc
lib=libvnc.so
username=ask
password=ask
ip=127.0.0.1
port=-1
#xserverbpp=24
#delay_ms=2000
[vnc-any]
...
[neutrinordp-any]
...
...
By default, the username
and password
parameters are set to ask
, which means the user will be prompted to enter their username and password to connect over RDP. Parameters, such as name
, username
, and password
, can be modified if necessary. For the initial RDP connection to the server, the default configuration will suffice.
Save and close the file when finished.
Now move to your user’s home directory if you are not there already:
- cd ~
Next, you will create a .xsession
file under /home/sammy
and add the xfce4-session
as the session manager to use upon login:
- echo "xfce4-session" | tee .xsession
tee
writes the echoed string "xfce4-session"
to the file .xsession
. The above configuration ensures that xfce4-session
is used as a session manager upon graphical login request. As a result of installingxfce
as your desktop environment, xfce4-session
serves as its session manager. If you don’t include this information in the .xsession
file, no session manager is chosen, and the RDP session will fail to connect to the graphical display.
Restart the xrdp server:
- sudo systemctl restart xrdp
Next, you will configure your firewall to allow remote connections from your public IP on port 3389
. An RDP connection serves on TCP/IP port 3389
. To access the remote server over RDP, you must allow port 3389
in your firewall.
First, find the public IP for your local machine:
- curl ifconfig.me
On Windows, use the Windows Command Prompt to run this command.
curl
places a request on ifconfig.me
that returns your public IP as an output:
Output...
your_local_ip
Next, allow access to the RDP port 3389
on your remote server, replacing your_local_ip
with the output of the last command:
- sudo ufw allow from your_local_ip/32 to any port 3389
Verify the status of your UFW
firewall:
- sudo ufw status
The output should look like the following:
OutputStatus: Active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
3389 ALLOW your_local_ip
OpenSSH (v6) ALLOW Anywhere (v6)
...
You have now enabled port 3389
to accept connections from your public IP. Next, you will test your local machine’s RDP connection to your remote server.
In this step, you will test the RDP connection from your local machine. The sections below include actions for testing the connection on Windows, macOS, and Linux machines.
To test the connection using the Remote Desktop Connection client on Windows, first launch the Remote Desktop Connection app.
Enter your remote server’s public IP and username into the fillable text boxes for Computer and User name. You may need to press the down arrow for Show Options to input the username:
Press the Connect button. If you receive an alert that the Remote Desktop can't connect to the remote computer
, check that you have turned on the Remote Desktop option in your system settings.
Press Yes if you receive the identity verification popup:
Then, enter your remote server’s username (sammy
) and the password you created for user sammy
during the initial server setup. Press Ok.
Once you have logged in, you should be able to access your Ubuntu Desktop environment:
Using RDP, you successfully connected to your remote Ubuntu server from your local machine. You can close it with the exit button when you have finished using your graphical desktop.
To test the connection using the Remote Desktop Connection client on macOS, first launch the Microsoft Remote Desktop Connection app.
Press Add PC, then enter your remote server’s public IP in the fillable box:
You can Add a user account when setting up the connection:
If you do not add a user during setup, you will be prompted for your user login credentials:
Press Yes to bypass the identity verification popup:
Once you have logged in, you can access your Ubuntu remote desktop. You can close it with the exit button when you have finished using your graphical desktop.
You will need an RDP client to test the RDP connection on a local Linux machine. First, install the remmina
RDP client for Ubuntu:
- sudo apt install remmina
Select y
if prompted to complete the installation. This command will install Remmina, an open-source remote desktop client on your Ubuntu system using apt
. For other Linux distributions, you can review the Remmina documentation for installation.
Once installed, launch the remmina
application on your local Linux machine and enter your remote server’s public IP in the fillable box. Press Enter on your keyboard to connect to your remote desktop.
Then, enter your remote server’s username (for this tutorial, the username is sammy
) and the password you created for the user during the initial server setup. Press Ok.
You may need to enter your user’s password again to unlock the remote desktop.
Once you have logged in, you should be able to access your Ubuntu Desktop environment.
Using RDP, you successfully connected to your remote Ubuntu server from your local machine. You can close it with the exit button when you have finished using your graphical desktop.
Once you have ensured the remote connection works, you can use this sequence whenever you need to use the graphical interface for your remote Linux server.
In this article, you configured xrdp to connect to a graphical desktop for your remote Ubuntu server over an RDP connection from a local machine.
Now, you can try configuring a VNC connection for your Linux server with How to Install and Configure VNC on Ubuntu 20.04. VNC is another option for remote connection to a Linux desktop.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
just a reference. if install xrdp on ubuntu and met the following errors:
Unable to locate a package using
apt
is the package repository hasn’t been added or updated. Enable universe repository may solve it:https://stackoverflow.com/a/78131508/6242896
Hi, If you are using Windows and want to RDP Ubuntu VM using Hyper V virtualization then please see my detailed answer on askubuntu.com/a/1503875/1751721 The steps are staright forward and no new installation is required.
Best Regards, Syed Nasir Abbas
Hi, thanks for this excellent work. is there a way to always send output to remote/client screen? (sometimes sub-windows open on server screen, instead of desired remote screen steps to repeat - VS-code runs on servers I open vscode on remote/client screen, it opens properly on remote screen then using vs-code I open directory, the directory selector screen open on server.
It’s extremely irresponsible to add
-y
to apt without giving the user the opportunity to realise what’s happening, and then let them inspect the output first. You, the author, cannot predict the output of every Ubuntu-based system out there, no matter how experienced you are.Case in point, the above commands cause
xorg
to be uninstalled on Linux Mint 19.1 setups.If you have the autologin activated you will have to disable it for the XRDP to work. Otherwise you will have issue with snap.
Managed to connect from Windows 10 to Ubuntu 22.04 by this step. But there pair of steps that should be done additionally:
a)
sudo adduser xrdp ssl-cert
b)
echo "sudo -u ${USER} xfce4-session" | tee .xsession
Pavel A.
Hi, Thanks for the subject training materials. I have followed the steps, but still, after connecting from my machine, which is Windows 10, to my remote Ubuntu machine, there is only a black screen. Please let me know if you have any suggestions on how to troubleshoot this issue .
Thanks,
This default doesn’t seem to work for me out of the box. Using a default Ubuntu 22.04 installation. Is that because of the shell that is being used by default?