The saga continues! If you'd like to be able to use Remote Desktop Connection (mstsc.exe) to connect to your WSL2 Ubuntu environment and run GUI applications, you can follow these steps:
- Update your Ubuntu system's packages before proceeding
sudo apt-get update && sudo apt-get upgrade -y
- Install a Desktop Environment (DE)
sudo apt-get install -y xfce4 xfce4-goodies
When prompted for a desktop manager, select LightDM.
(feel free to use a different DE if you want)
- Install the Mesa Driver and Extras:
sudo apt-get install mesa-utils mesa-vulkan-drivers mesa-vdpau-drivers mesa-va-drivers
- Run each of the lines below separately:
sudo apt-get install xrdp
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/max_bpp=32/#max_bpp=32\nmax_bpp=128/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/xserverbpp=24/#xserverbpp=24\nxserverbpp=128/g' /etc/xrdp/xrdp.ini
- Edit the startwm.sh file so that the DE you installed in step 1 will run:
sudo nano /etc/xrdp/startwm.sh
- Comment out the following lines with a # character:
test -x /etc/X11/Xsession && exec /etc/X11/Xsession
exec /bin/sh /etc/X11/Xsession
- Add to the bottom of the file the command needed to start the DE you installed in step 1. If you went with XFCE, it'll be:
startxfce4
Your startwm.sh
file should now look like this:
- Add the new xrdp user to the ssl-cert group:
sudo adduser xrdp ssl-cert
If you don't do this you'll get a security error whenever you try to connect later.
- Enable dbus (run one line at a time):
sudo systemctl enable dbus
sudo /etc/init.d/dbus start
- Start up the xrdp server:
sudo /etc/init.d/xrdp start
You should now be ready to connect!!
- Open up Remote Desktop Connection (mstsc.exe) and connect to
localhost:3390
. Be sure to replaceyour-ubuntu-username
with your actual Ubuntu username.
- Click on 'Connect'. You will be prompted to accept the certificate that is already located on your system. Do so to continue. Afterwards you will be brought to an xrdp login page:
- Enter your Ubuntu user's password and click 'Ok'.
You should should now be able to see your Ubuntu desktop!
If you restart your machine or WSL, you will no longer be able to connect to your RDP server as it will no longer be running. 😱
For ease of starting it back up you can do one of the below steps:
Add this line to your runtime configuration file (.bashrc
/.zshrc
/etc):
alias start-rdp="sudo systemctl enable dbus && sudo /etc/init.d/dbus start && sudo /etc/init.d/xrdp start"
After reopening the terminal you can then type start-rdp
whenever you want to run the server.
Add this to the bottom of your runtime configuration file (.bashrc
/.zshrc
/etc):
sudo systemctl enable dbus && sudo /etc/init.d/dbus start && sudo /etc/init.d/xrdp start && clear
The RDP server will now attempt to run every time you open a terminal. You will also be asked for your password every time you open a terminal since the above commands contain sudo
. 😅
If desired, resolve it with the following:
Run sudo visudo
Add the following line to the bottom:
YOUR-USERNAME ALL=(ALL) NOPASSWD: ALL
This will make it so you will not be asked for a password whenever using sudo
for any command. Feel free to replace the last ALL
with the paths to the executables in the commands you've added to your runtime configuration if you want to be more granular about it.