Ubuntu (Linux) RDP GUI with Windows WSL

This article explains the steps to setup Ubuntu virtual machine on Windows using Window's Subsystem for Linux (WSL) and be able to connect to Ubuntu using Window's builtin Remote Desktop Protocol (RDP) app.

Enable WSL on Windows:

  1. Start -> Search -> Turn Windows feature on or off
  2. Virtual Machine Platform -> Tick
  3. Windows Hypervisor Platform -> Tick
  4. Window Subsystem for Linux -> Tick
  5. Click OK
  6. Wait for some installations to complete
  7. Restart Windows

Install Ubuntu:

Start -> Terminal and execute

wsl.exe --update

wsl.exe --install -d Ubuntu

When prompted 'Create a default Unix user account' set any username as 'windows'

Type a password

Retype the password

Wait for installation to complete

Verify Ubuntu:

wsl.exe --list --verbose

Launch Ubuntu:

wsl.exe -d Ubuntu

or through UI

Start -> Ubuntu

Setup GUI for RDP:

Update packages using commands

sudo apt-get update

sudo apt-get upgrade -y

Install and setup tasksel:

sudo apt-get install -y tasksel

sudo tasksel

Use Up and Down Arrows to choose the Desktop environment like GNOME or Xfce or KDE Plasma. Select only one desktop environment, as selecting multiple causes configuration issues.

Use Space key to tick or untick

Use Tab bar to go to OK button

Press Space key to click OK button

Wait for the tasksel command to complete desktop installation and setup, as this will take a long time to complete.

Install and setup xrdp:

sudo apt-get install -y xrdp

sudo systemctl enable xrdp

sudo systemctl restart xrdp

Restart Ubuntu virtual machine from a new Windows Terminal:

Terminate single Ubuntu virtual machine

wsl.exe --terminate Ubuntu

or

Shutdown entire wsl instances

wsl.exe --shutdown

Check shutdown status

wsl.exe --list --verbose

Start Ubuntu virtual machine and check xrdp service status

wsl.exe -d Ubuntu

sudo systemctl status xrdp

Get the RDP connection details of Ubuntu virtual machine:

Find the ip address of virtual machine from Windows Terminal using

wsl.exe -d Ubuntu hostname -I

or find the ip address of virtual machine from within Ubuntu virtual machine

ip addr show eth0 | grep inet

Find the xrdp port from within Ubuntu virtual machine

grep "port=" /etc/xrdp/xrdp.ini

The default port is 3389, but sometime the port may be 3390

Connect from Windows using RDP:

Start -> Search -> Remote Desktop Connection

Enter the Ubuntu virtual machine ip with port as Computer. Eg: 172.31.128.103:3389 or 172.31.128.103:3390

Select the Session type as Xorg and enter the Ubuntu username and password when prompted

Type in the Ubuntu password once again if prompted

Clean up of WSL and distributions:

Delete a particular virtual machine:

wsl.exe --unregister Ubuntu

Delete all virtual machines:

wsl.exe --list --quiet | ForEach-Object { wsl --unregister $_ }

Uninstall wsl application itself:

wsl.exe --uninstall

Using WSL version 1 (Legacy):

If you get the following error

WSL2 is not supported with your current machine configuration.

Please enable the "Virtual Machine Platform" optional component and ensure virtualisation is enabled in the BIOS.

Enable "Virtual Machine Platform" by running: wsl.exe --install --no-distribution

For information please visit https://aka.ms/enablevirtualization

Error code: Wsl/InstallDistro/Service/RegisterDistro/CreateVm/HCS/HCS_E_HYPERV_NOT_INSTALLED

Try using legacy version 1 of wsl

wsl.exe --set-default-version 1

wsl.exe --install -d Ubuntu

Comments

Popular posts from this blog

Export/Backup Ollama Model

JSON with curl and jq

Import self signed in Linux for Chrome / Chromium headless testing