Use X11 forwarding with WSL

From IIHE Wiki
Jump to navigationJump to search

About

This page will help you to install Windows Subsystem for Linux and X11 forwarding on Windows 10.
Windows Subsystem for Linux can run a complete Linux OS inside Windows.
VCXSVR will help you to have X11 forwarding enabled.

Pre-requities

  • Windows 10 version or more recent.
  • Administrative rights on your computer.
  • Chocolatey, the Windows package manager installed.

Install Chocolatey

Open a Powershell shell as Administrator by pressing the following keys :

  • Windows key + X

Paste the following in the Powershell window :

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

Once Chocolatey is installed close the Powershell window.

More detail is available here

Install WSL & VCXSVR

Open a Powershell shell as Administrator by pressing the following keys :

  • Windows key + X

On the Powershell window type the following :

  • choco install vcxsrv wsl -y

This command will enable WSL and install VCXSRV to enable X11 forwarding.

Leave the Powershell window open since we still need it to install your distribution.

Install your Linux distro on WSL

Now you need to choose witch distro you want to install on your computer :

  • Ubuntu 18.04
  • Ubuntu 18.04 ARM
  • Ubuntu 16.04
  • Debian GNU/Linux
  • Kali Linux
  • OpenSUSE Leap 42
  • SUSE Linux Enterprise Server 12
  • Fedora Remix for WSL

Once you choose the distro you can download and install it in one Powershell command :

  • (To download and install) Ubuntu 18.04

USE :

choco install wsl-ubuntu-1804 -y

  • Ubuntu 18.04 ARM

Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804-arm -OutFile Ubuntu1804arm.appx -UseBasicParsing; Add-AppxPackage .\Ubuntu1804arm.appx

  • Ubuntu 16.04

choco install wsl-ubuntu-1604 -y

  • Debian GNU/Linux

Invoke-WebRequest -Uri https://aka.ms/wsl-debian-gnulinux -OutFile Debian.appx -UseBasicParsing; Add-AppxPackage .\Debian.appx

  • Kali Linux

Invoke-WebRequest -Uri https://aka.ms/wsl-kali-linux-new -OutFile Kali.appx -UseBasicParsing; Add-AppxPackage .\Kali.appx

  • OpenSUSE Leap 42

Invoke-WebRequest -Uri https://aka.ms/wsl-opensuse-42 -OutFile Opensuse.appx -UseBasicParsing; Add-AppxPackage .\Opensuse.appx

  • SUSE Linux Enterprise Server 12

Invoke-WebRequest -Uri https://aka.ms/wsl-sles-12 -OutFile Opensuse.appx -UseBasicParsing; Add-AppxPackage .\Opensuse.appx

  • Fedora Remix for WSL

You have to first get the appx file here : https://github.com/WhitewaterFoundry/WSLFedoraRemix/releases/ Once you got the file you can install it using : Add-AppxPackage <packagepath>\<packagename>

Starting The distro

  • Once you installed the distro you can start it from the Start menu :

  • You have to set a username and password Note that you can't use the same username as your Windows username:

  • Let's update the software on the distro (Debian or Ubuntu) :

apt update && sudo apt upgrade -y

  • Install X11 apps to test X11 Forwarding :

sudo apt install x11-apps -y

  • Enable X11 forwarding :

echo "export DISPLAY=localhost:0.0" >> ~/.bashrc

  • Now exit your terminal and start the distro again.
  • Start VCXSRV on Windows and start xclock on the distro terminal :

You should see a clock appears on Windows.

  • Now you have a complete Linux distro installed on Windows 10 and X11 forwarding enabled.