Developing for Windows from Linux
Here is how you setup your Linux computer to code, build and debug apps for Windows
Wait.. what?
Yeah.. you read that right! You can use the comfort of your Linux computer, with your multi-monitors and tools setup just right, to develop Windows stuff. No, using a remote desktop doesn’t count. That’s laggy and you can’t use your Linux tools.
I am leveraging SSH here, which is nothing new. But what I found out recently is that it is now insanely easy to setup thanks to the hard work done by.. err.. Microsoft ¯\_(ツ)_/¯
What exactly is possible?
I will be using the following two key pieces of technologies for this setup:
- Window’s in-build OpenSSH server
- VS Code’s “Remote Development” extension pack
You can probably see where this is going now. So, basically we will SSH into Windows and develop via VS Code. I am gonna describe the setup process and show you some of the insane possibilities that it enables.
Just to whet your appetite, this is my setup that inspired me to write on this topic:
- I needed to develop a Machine Vision based Python app for Windows. It’s Windows only because I had to use a video camera that only works in Windows. Therefore WSL was not an option.
- This Python app would need to expose a web API (e.g. REST endpoints on port 5000)
- I needed to develop a React JS front end that consumed this web API
A sane person would just setup everything on Windows and called it a day. But I am less fortunate and insisted that I develop from my Ubuntu workstation. So I went about and setup the “setup” shown above. This is what it looks like on Ubuntu with the two IDEs and browser.
Break points work on both IDEs and I am able to access the hardware attached to my Windows box. Unholy?.. Yes, but oddly cathartic.
Let’s move on to the setup details.
How to set it up
Setup OpenSSH server on Windows
This might surprise you if you are not upto date with all the OpenSource projects that Windows have lately been including with Windows; but I kid you not; Microsoft includes an OpenSSH Server implementation with Windows 10. To enable it; just run the PowerShell scripts from:
Then if you are not a masochist, change the default shell from the default Windows Command Shell to PowerShell:
You will notice that the Windows OpenSSH server implementation doesn’t support X11 forwarding, but local port forwarding is supported; which is sufficient and understandable.
Next we need to setup key based SSH authentication for our Linux user. To do so, copy your SSH pub key from our Linux user to the Windows. Now we need to copy the contents of the pub key to the authorized_keys file on Windows. The location if which is “C:\Users\<user>\.ssh\” for regular users and “C:\ProgramData\ssh\administrators_authorized_keys” for local admin accounts. If your account is an admin account, you will need to further limit the permissions of that “administrators_authorized_keys”. Run the following PS commands to fix the permissions:
$acl = Get-Acl C:\ProgramData\ssh\administrators_authorized_keys
$acl.SetAccessRuleProtection($true, $false)
$administratorsRule = New-Object system.security.accesscontrol.filesystemaccessrule("Administrators","FullControl","Allow")
$systemRule = New-Object system.security.accesscontrol.filesystemaccessrule("SYSTEM","FullControl","Allow")
$acl.SetAccessRule($administratorsRule)
$acl.SetAccessRule($systemRule)
$acl | Set-Acl
Credit: https://www.concurrency.com/blog/may-2019/key-based-authentication-for-openssh-on-windows
Linux setup
Verify that you can SSH to your Windows instance without a password.
Now all you need to do is install VS Code and the Visual Studio Code Remote Development Extension Pack. It’s great! Details about how to use it can be found in the VS Code docs: https://code.visualstudio.com/docs/remote/ssh.
VS Code automatically does local port forwarding so you don’t need to set it up in your SSH config.
That’s the entire setup!
The possibilities
- You can use this with Windows VMs or physical machines
- You can access hardware resources on the Windows side that would otherwise not work on Linux.
- You can local port forward ports between Linux and Windows, so Linux can see services on Windows and vise versa
- You can develop using any language that VS Code supports
The possibilities are endless! Thank you Microsoft.. I no longer need to work on Windows to develop for Windows ♥