Running Linux inside Windows 10 with Visual Studio Code

Like most of the users in the world, I’m running a Managed Window 10 client, we enforce many polices such as applocker and more to enforce policies. This can sometimes be an problem when working with developer tools. Due to this problem businesses often look the other way when it comes to developers and their clients. From personal experience I see that They are often excluded from the overall security measures or just not joined into the domain at all.

According to Stack Overflow about 45% of people identifying as ”Professional Developers” run Windows as their main desktop operating system. If most of these are exluded from the standard security we have a major issue.

The main issue is not that developers need to execute/install unsigned or generally untrusted tools and compile and execute code. The problem is that developers get exceptions to run this in their standard domain-joined Windows clients. The same Windows client that has access to all company resources. It only requires a simple user error to install some virus or otherwise malicious program and the computer is comprimised. Or we could just block everything and stop the productivity of our developers.

Neither of the above is clearly a good option, so what’s the solution?

Windows Subsystem for Linux (WSL) 2

WSL has existed for some time, but with windows Version 2004 (build 19041) WSL 2  introducing important changes such as a real Linux kernel through a subset of Hyper-V features. This allows us to do some cool stuff like starting VS Code from inside the Linux operating system, giving us a terminal with our windows folders mounted.

There are several blogposts out there on how to install a linux distro using wsl2, but I’d like to combine some of them and show what has worked for me.

Prerequisites

WSL2 has some pre-requisites. First you need to upgrade your windows client to atleast build 19041 (released may 2020).

When that’s done simply run the powershell script (elevated) on your machine and then reboot.

Now you need to install your linux distro of choice. I went with Ubuntu 18.04 (since this is the latest ubuntu that supports Powershell core). Linux can be installed using windows store, so just go to the store and download + launch the desired distro. After that you need to configure the distro to run wsl version 2.

The below powershell script launches the Ubuntu 18.04 store site and waits for you to initalize the os. then configures wsl. If you choose another distro, then type wsl –version –verbose to find out the name,

Now that you’re done you should be able to see ubuntu from the Windows Terminal, or if you’re just using cmd or powershell simply type ”wsl” and you should be able to enter the linux environment.

Windows Terminal Linux

And even though you can access your local files, only the c:\ becomes mounted, and as such the vm cannot read company documents and files in case of some security breach within the linux vm.

Now you just install all the tools you need, the lines of code below installs my most used. Powershell Core 7, Kubectl, Terraform, Az CLI.

Now that that’s done you’re probably wondering how to run Visual Studio Code with integration to your Windows Client.

To do this, simply type ”wsl code .” from an elevated promt, cmd or powershell. If you’re actively working from within your linux machine simply type ”code .” and VS code will start.Visual Studio Code

All that’s left now is to start developing!

I hope this was helpful!

 

 

 

 

 

 

Disclaimer: All information on this blog is offered "as is" with no warranty. It is strongly recommended that you verify all information and validate all scripts in isolated test environments before using them in production environments.