| tags: [ Software Docker WSL2 Windows Terminal SSH ]
Using WSL2
This article documents the setup of WSL2 for local and remote development. Local development is supported by Docker. For remote development, WSL2 effectively acts as a bridge. Remote development is done via SSH with support for X11 forwarding. This allows X11 applications to be run on the remote host and display on the Windows desktop.
1. Install WSL2
- Install WSL2
- Install Ubuntu from the Microsoft Store
Convert to WSL2
wsl --set-version Ubuntu 2
Verify WSL version
wsl --list --verbose
2. Install Docker
The following will make Docker available from WSL2.
- Download the latest stable release
- Follow the Docker WSL2 instructions
3. Install Windows Terminal
- Install Windows Terminal from the Microsoft Store[1]
- Open Windows Terminal
Edit Settings
4. Setup SSH X11 Forwarding
- Install VcXsrc
- Run XLaunch
- Set display number to
0
- Disable access control
- Save configuration
- Open saved configuration to run VcXsrc
- Set display number to
- Open a WSL terminal
Configure
$DISPLAY
by adding the following to your~/.bashrc
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0.0
This sets the DISPLAY to the IP address of the Windows host.
Configure SSH
- Test
SSH
ssh remote-host
Run an X11 application
xlogo
It should display on your Windows desktop.
5. Setup Pageant
Download wsl2-ssh-pageant
cd ~/.ssh/ curl -LO https://github.com/BlackReloaded/wsl2-ssh-pageant/releases/download/v1.0.0/wsl2-ssh-pageant.exe chmod +x wsl2-ssh-pageant.exe
Install
socat
sudo apt-get install socat
Add
wsl2-ssh-pageant
to your~/.bashrc
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock ss -a | grep -q $SSH_AUTH_SOCK if [ $? -ne 0 ]; then rm -f $SSH_AUTH_SOCK setsid nohup socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:$HOME/.ssh/wsl2-ssh-pageant.exe >/dev/null 2>&1 & fi
6. SSH into WSL2
Scott Hanselman has a great article on accessing WSL2 via Windows OpenSSH server titled THE EASY WAY how to SSH into Bash and WSL2 on Windows 10 from an external machine. However, it only supports Bash. It doesn’t support alternative shells like Zsh.
The trick is to change the Windows OpenSSH server default shell to C:\Windows\System32\wsl.exe
instead of C:\Windows\System32\bash.exe
.
This will use whatever shell WSL2 has been configured to use.
- Windows Terminal v1.4 as of this writing. ↩