Linux on Windows: WSL with Desktop Environment via RDP

Linux on Windows: WSL with Desktop Environment via RDP

WSL (Windows Subsystem for Linux) is very common these days especially with the new that Windows will ship a Linux kernel with WSL 2.0!

Installing a Linux distro as WSL is easy via the Microsoft App Store and there are plenty of tutorials out there for it.

Most of the resources cover the access via Shell, Terminal, Hyperterminal or other console based tools to the WSL.
Running GUI software is possible and there are resources describing how to archieve this via VcXsrv (see chapter in this post of mine).

But what if you:

Want to have/access a Desktop environment on WSL?

You can use any Desktop Environment you want, I will be using Xfce in this example because it is lightweight.

Here is the quick rundown of all commands and steps, explained in the sections below. One is for Kali Linux, the other is for the Debian based distros (Debian, Ubuntu, …).

For Kali:

sudo apt update && sudo apt -y upgrade
sudo apt -y install kali-desktop-xfce
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
sudo /etc/init.d/xrdp start

For other debian based distros:

sudo apt update && sudo apt -y upgrade
sudo apt -y install xfce4
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
sudo /etc/init.d/xrdp start

And then connect via RDP localhost:3390 to your desktop.

Connect to WSL DE via Xrdp

Login to WSL DE

Detailed steps

Updating the system and installing Xfce4

sudo apt update && sudo apt -y upgrade
sudo apt -y install kali-desktop-xfce
sudo apt -y install xfce4

The first command updates the source list and the packages. Always important, I will not explain this.
The sudo apt -y install kali-desktop-xfce installs a Kali Linux specific version of Xfce4 and sudo apt -y install xfce4 will install the Xfce4 package for debian based distros.

Installing Xrdp

sudo apt-get install xrdp

Xrdp is an open source remote desktop solution and also very lightweight and easy to configure. This command will install the package and setup the default configuration with port 3389.

Configuring 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
sudo /etc/init.d/xrdp start

Copy the config file as backup before the changes, change the port from 3389 to 3390 and for quality reasons increase the bpp from 24 to 128. You can play with those settings but since this is a local connection, the speed should not be worse with those settings.
And finally restarting the xrdp service to apply the changes.

Now you can connect via localhost:3390 and the credentials of your WSL account via RDP! ?

Desktop of WSL via xrdp

Why the port change from 3389 to 3390?

Two reasons: security and sometimes port 3389 is used by a process on wsl and you get the message

Your computer could not connect to another console session on the remote computer because you already have a console session in progress.

Benefits of RDP here

Even though you can run GUI software via XServer in a window, sometimes it is more convenient to have the full desktop environment accessible.
Also you can restore a previously disconnected session easily and do not have to close the console (let processes running for example).

Source : Linux on Windows: WSL with Desktop Environment via RDP – DEV Community ?‍??‍?