wsl

WSL handy commands

Marti Sec
Mar 31, 2021
windowslinuxfix

Often WSL2 does not work well anymore, and those commands have saved me some time and headaches.

If you have messed-up something (e.g. sudo), login to the WSL as root (from windows CMD)

C:\>wsl -u root

Restart WSL2, sometimes needed when you can't connect from your windows to the servicess runing on it (e.g. to access a localhost website running on WSL)

C:\>wsl --shutdown

Increase limit of open files

WSL does not support to do it the usual way, so this is what it works for me (ubuntu and WSL2). Source: https://github.com/microsoft/WSL/issues/4575

$ mylimit=200000
$ sudo prlimit --nofile=$mylimit --pid $$; ulimit -n $mylimit