Linux on Windows: WSL with Desktop Environment via RDP
Tags: windows, wsl, linux, configuration
Published: 2019-07-17 11:06:00

WSL (Windows Subsystem for Linux) is very common these days especially with the new that Windows will ship a [Linux kernel](https://github.com/microsoft/WSL2-Linux-Kernel) with [WSL 2.0](https://docs.microsoft.com/de-de/windows/wsl/wsl2-about)!

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](https://dev.to/darksmile92/run-gui-app-in-linux-docker-container-on-windows-host-4kde#install-vcxsrv-and-configure-it) 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](https://www.xfce.org/) 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:
```bash
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
```

**EDIT: 08/2022**
As [Elvis Van](https://dev.to/elvisvan) mentioned in the [comments](https://dev.to/elvisvan/comment/212lj), there is a package for Kali linux now targeting specifically this case: [kali-win-kex](https://www.kali.org/docs/wsl/win-kex/). It takes care of the full setup of all Kali components and configurations to give you the Kali Desktop experience under WSL2.

For other debian based distros:
```bash
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](https://thepracticaldev.s3.amazonaws.com/i/ho6kk30r5w1azj1pgvfv.png)

![Login to WSL DE](https://thepracticaldev.s3.amazonaws.com/i/nuteksr5x3tbmewsic7s.png)


### Detailed steps

#### Updating the system and installing Xfce4
```bash
sudo apt update && sudo apt -y upgrade
```
```bash
sudo apt -y install kali-desktop-xfce
```
```bash
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
```bash
sudo apt-get install xrdp
```
[Xrdp](http://www.xrdp.org/) 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
```bash
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](https://thepracticaldev.s3.amazonaws.com/i/3qds38rrmzc6kaya8mym.png)

###### 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).

Let me know your thoughts on this topic!