Installing Windows Subsystem for Linux (WSL) on Windows 10

Microsoft has been doing a lot to promote linux  interoperability on windows.  I see this as a great step in the right direction, after decades of a closed and exclusive culture that has been a pain for cross-os users like myself.

Here is a quick and dirty rundown of how (March 2019) to install Ubuntu on Windows 10:

See here for the full rundown: https://docs.microsoft.com/en-us/windows/wsl/install-win10

Install the Windows Subsystem for Linux

Before installing any Linux distros for WSL, you must ensure that the “Windows Subsystem for Linux” optional feature is enabled:

  1. Open PowerShell as Administrator (search for Powershell, right click, run as administrator), and run this command:
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
    
  2. Restart your computer when prompted.

Install your Linux Distribution of Choice

Go to the Microsoft Store and search for Ubuntu.  Install it.

Once you are in Ubuntu, there are a few things to do that will make everything nicer…

Update Ubuntu and setup ssh server
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install openssh-server
sudo service ssh start

Fix character encoding issue (until this is fixed upstream)
sudo gunzip –keep /usr/share/i18n/charmaps/UTF-8.gz
sudo dpkg-reconfigure –frontend=noninteractive locales

Setup SSH under your user
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
(put your public key in there)
Setup PuTTY
You can then configure PuTTY to connect to 127.0.0.1 port 22 with your username and key (ideally from Pageant)
You can access your c drive under /mnt/c/
You can access your desktop using /mnt/c/Users/YOU/Desktop
This enables you to write convenient scripts in ubuntu that affect windows files on your desktop for example.

How to Generate a SSH Keypair (public/private) on Windows

Have you ever been asked to generate an SSH keypair in order to gain access to a server, github, or an sftp site?

Here is how on windows.

First, download puttygen.exe from here:

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

 

Second, run puttygen.exe and follow these instructions:

(except, put your name instead of Sharon)

(On step 8, copy and paste this and send it to whomever requested it)

puttygen instructions

Optimal PuTTY Settings for SSH Connections to Linux

PuTTY is a great program.  I think it tops the cake for most-useful-utility-on-windows that I have ever encountered.  I’ve used it to connect to telnet, ssh, linux, unix, windows, hypervisors, and even IBM iSeries (AS-400).  However, despite all the cool things one can do with PuTTY, the default out-of-the-box-settings leave a good bit to learn.

For a long time, I put up with some less than optimal settings.  But over time, I learned what worked best for me.  The purpose of this post is to share that with you.

Enjoy!

Download from: http://www.chiark.greenend.org.uk/~sgtatham/putty/

Hint: I prefer the windows installer.  However, whatever you do, make sure you get the whole suite (unless you know you don’t need it)

Launch PuTTY and configure “Session” section

user@host is handy for auto-login.  I prefer to place my server name before my username in the saved sessions because the sort order will be maintained as the list grows.

Configure the “Terminal > Bell” section

I have found it preferable not to disable the bell if it is overused.

Configure the “Window” Settings

This is one of the most important settings.  The default of 200 lines of scrollback is just not enough.  I find 20000 to be more useful.  Also, the window size should be set according to your screen size and preferences.

Configure “Window > Appearance” settings

I find that the Luicida Console 14 point font is very easy on the eyes.  Keep in mind I’m usually using a 27″ or 30″ display at 2560 pixels wide, so I can afford the extra size of 14pt.  However, even on smaller screens, I still find it nicer to be able to read effortlessly and see less than the other way around.  Just give it a try :)

Configure the “Window > Translation” settings

As of a few years ago, Linux began to use UTF-8 character encoding by default.  This means that if your terminal is set to latin1 or similar, then each single multi-byte-character is literally interpreted as multiple latin1 characters, mostly drawn as out-of-place accented letters and various symbols.

So in my experience, it is best to use UTF-8 when connecting to Linux.

Configure “Window > Selection” settings

You need to decide here if you want an important safety precaution.  Under the “Compromise” setting above, right-click will paste whatever is on the clipboard… even if you were just blogging about sudo rm -rf /

So, think that over pretty hard.  The first option of “Windows” will bring up a right-click menu with a convenient “Paste” option.  Also, you can simply us SHIFT+INSERT to paste in PuTTY.

Configure “Window > Colours” settings

If you can read dark-blue-on-black, then your vision is in another “spectrum” than mine.  Check out the difference here:

Simply select “ANSI Blue” and change the RGB values to 112, 112, 255.

Configure “Connection” settings

It is helpful to send a null packet every once in a while to keep sessions alive.

Configure “Connection > SSH” settings (Update)

David Aldrich pointed out in a helpful comment that  “I also think it is probably worth enabling SSH compression if working over a slow connection.”

Configure “Connection > SSH > Auth” settings

If you use SSH Agent forwarding (eg pagent) to allow you to “hop” from one server to another, then PuTTY must be told to enable Agent Forwarding.  There are some security issues with this setting when connecting to an untrusted server, so please understand them first.

Configure “Connection > SSH > Tunnels”

If you want to connect to a MySQL or PostgreSQL service running on the host you are connecting to, but have all communication encrypted and sent via SSH tunnel, here is how to set that up.

Keep in mind that your Windows OS you are on must have the source port free, so if you are ALSO running MySQL locally, then pick a different local port number like 13306.

Once your SSH session is established, then you can connect to localhost port 13306 and it will be tunneled to the remote server on 3306.  Cool!

Finally!!! Don’t forget to save your session.

(hint: press the “Save” button)

And that’s it!  The basic PuTTY settings that I use which work quite nicely.

Hope this helps.