Use SSH & X11 forwarding on Windows with WSL
WSL
Windows Subsystem for Linux (WSL) is a feature of Windows that allows developers to run a Linux environment without the need for a separate virtual machine or dual booting.
There are two versions of WSL: WSL 1 and WSL 2. WSL 1 was first released on August 2, 2016, and acts as a compatibility layer for running Linux binary executables (in ELF format) by implementing Linux system calls on the Windows kernel.
Prerequisites
- Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11.
WSL Configuration
- Start an elevated terminal by pressing on Windows key + X and choose terminal (admin) then type the following command :
wsl --install
This command will install all needed components for WSL and Ubuntu 22.04 distribution by default.
if you prefer another distribution you can specify it with the -d argument (more info at the end of this section).
- After the configuration is completed you need to restart your computer.
- After having restarted your computer you need to specify a username and a password then your WSL Distribution is ready to use.
- To connect over SSH with X11 forwarding use the -X argument in your SSH command :
ssh username@hostname -X
Install another distribution
You ca use the -d argument to specify another distribution to be installed by WSL, use the following command to get the distribution that are available :
wsl --list --online
At the time of writing this documentation the following distribution can be installed using WSL :
NAME FRIENDLY NAME Ubuntu Ubuntu Debian Debian GNU/Linux kali-linux Kali Linux Rolling Ubuntu-18.04 Ubuntu 18.04 LTS Ubuntu-20.04 Ubuntu 20.04 LTS Ubuntu-22.04 Ubuntu 22.04 LTS OracleLinux_8_5 Oracle Linux 8.5 OracleLinux_7_9 Oracle Linux 7.9 SUSE-Linux-Enterprise-Server-15-SP4 SUSE Linux Enterprise Server 15 SP4 openSUSE-Leap-15.4 openSUSE Leap 15.4 openSUSE-Tumbleweed openSUSE Tumbleweed
For example to install Debian use the following command :
wsl --install -d debian