Windows WSL
Highlights
Setup after laptop reboot
# enable ssh
$ sudo /etc/init.d/ssh restart
# restart docker
sudo service docker start
# re-register ssh keys with ssh-agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa_gabepublicResynch wsl clock when out-of-synch
$ sudo hwclock -s
# if it does work, do the following
# From cmd prompt
wsl --shutdown
# then restart
wslSummary
Setup
Source: Install WSL command
Use
winverto find the Windows versionWindows 10 Version 20H2 (OS Build 19042.2006)
The original
wsl status; Note: this will change afterwsl install.
Turn-on Hyper-V, then Reboot Source: [REF-4]

Check system info
Install Ubuntu and Reboot
After reboot, a linux ubuntu terminal open to complete the ubuntu OS installation
Ubuntu virtual hard disk
They are stored in %USERPROFILE%\AppData\Local\Packages<distribution package name>\LocalState\ext4.vhdx For Ubuntu, the distribution package name is CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc
List all available distributions from Powershell:
Install ssh
Enable ssh - from the linux terminal
Go to /etc/ssh folder, and modify sshd_config to the following:
Generate host keys for ssh; otherwise, the following error may occur during
ssh restart:sshd: no hostkeys available -- exiting.
Restart the ssh server
In addition to linux installation, the
wslwas also updated; now we can issue the following:
Check how to Connect Windows File Explorer to the Ubuntu drive; see Connect Windows to Linux;
Troubleshooting
After running the wsl --install -d Ubuntu command above, a terminal window will open that is going to install the ubuntu, BUT an error occur:
Virtual hard disk files must be uncompressed and unencrypted and must not be sparse
After running wsl --install -d Ubuntu command, even though it fails, the "Ubuntu" icon will show up on the start menu.
To solve the "virtual hard disk uncompressed and unencrypted" issue, do the following:
This is recommended by Ref-3, and it worked
Open up File Explorer and navigate to
C:\Users\YOUR_USER\AppData\Local\Packages\CanonicalGroupLimited...Right click on
LocalState, then select Properties, then AdvancedEnsure
Compress contents to save disk spaceandEncrypt contents to secure dataare both deselectedClick
OK, thenApply, to Apply changes to this folder onlyFrom the start menu, find and click "Ubuntu". A terminal window will open and start installing Ubuntu, as follow:
Update
Connect Windows to Linux
Open File Explorer, and type
\\wsl$File explorer will show the Linux instance and the folder structures
Connect Linux to Windows folders
From the Linux terminal
Use Termius or putty to connect to linux
For the host address, enter localhost.
VS Code Connect Remotely to WSL
Install extension "Remote WSL" if not already. Not sure if need to restart VS code after installation.
Once installed, a button should appear on the bottom left hand corner (><) that can be used to "Open a Remote Window". This will open a new VS code
To open a Linux terminal within the already running VS code, click the (+) dropdown located on the top right hand side of the terminal tab, and select the distro "Ubuntu (WSL)"
Also see this article
From VS code connect to WSL

Then open folder and choose WSL folder
Start WSL after Windows reboot
After rebooting Windows, the File Explorer cannot connect the Linux folder (see Connect Windows to Linux) until WSL is started.
To start WSL, for example after rebooting Windows, open PowerShell in the administrator mode, and issue the following command:
The PowerShell terminal now becomes the WSL Ubuntu terminal.
Note: to open another Ubuntu terminal, from the Windows "Start" menu, find & click "Ubuntu for Windows", that will open the Ubuntu console
[Alternative] PowerShell is limited in functionality and lacks features such as: multiple tabs, panes, etc. Try install the "Windows Terminal". Using the windows terminal, to open "Panes" within the same tab, [alt-click-dropdown-selectType] to open a new pane of the selected terminal type; [ctrl-shift-w] to close the focused pane; [alt-arrowKey] to move between pane; [alt-shift-arrowKey] to resize pane.
From the Ubuntu terminal, start the SSH service so that we can connect to wsl Ubuntu from the SSH terminal (such as: putty or termius)
Now, use the File Explorer should connect to Linux folder.
Repair or Reset WSL Linux instance
Click the Start button, then click Settings.
Click on Apps button, and then search for Ubuntu (or your distribution name) under Apps & features.
Under search results, click on Ubuntu (or your distribution name) and then click on Advance options.
Choose "Repair" or "Reset"
Best Practice - Set up a WSL development environment
[REF-5] Microsoft: Set up a WSL development environment]
Install GUI desktop in WSL2 Ubuntu
Source: - [Referenced here] WSL2 Ubuntu GUI - Install GUI Desktop in WSL2 Ubuntu 20.04 LTS in Windows 10
From the ubuntu terminal, setup Xfce. Note: after completion of the installation, we will be able to RDP (Windows remote desktop) into the Ubuntu GUI desktop
Update the Distro installation and remove previous install of xrdp
Install Xrdp
Install Xfce , select lightdm or gdm3 as per your preference when asked; optional to add
xfce4-goodies.
Open the start script,
/etc/xrdp/startwm.sh, and comment the last 2 lines, and add one new entry, as shown below
Modify the port to 3390 in the xrdp config
Start the
dbusandxrdp
Open RDP and connect to localhost:3390
How-to
cannot ssh into wsl after windows update
windows update changes the wsl ssh config causing ssh from windows using (putty, termius, etc.) to fail. SSH should be possible with localhost:22, and the linux userid/password.
To fix the issue, do the following:
From the start menu, find Ubuntu and open
Go to /etc/ssh folder, and modify sshd_config to the following:
Restart the ssh server
Source: https://stackoverflow.com/questions/65196276/sshing-from-windows-10-into-wsl2-ubuntu
Error due to WSL time out of sync or not updated
An error occurred (SignatureDoesNotMatch) when calling the GetCallerIdentity operation: Signature expired: 20230804T145316Z is now earlier than 20230805T044911Z (20230805T050411Z - 15 min.)
Run the following command; issue should have been fixed by wsl; see https://stackoverflow.com/questions/65086856/wsl2-clock-is-out-of-sync-with-windows
References
[REF-1] Youtube - How To Run Linux Code on Windows with WSL 2 & VS Code
[REF-2] Microsoft - Windows Subsystem for Linux Documentation
[REF-5] Microsoft - Set up a WSL development environment
Last updated