Skip to main content

Using the Linux Subsystem (WSL) in Windows 10

By Tuesday October 9th, 2018November 4th, 2018Developer's Corner

Overview

The following article will be a comprehensive guide for setting up and using the Linux Subsystem in Windows 10 with Xshell. (If you know what you’re doing and only want the quick step-by-steps, scroll down to Quick Deployment Guide near the bottom).

Using the SSH protocol, you can connect to the Windows system by either installing the SSH server program for Windows or you can take advantage of the Linux Subsystem recently provided in Windows 10. This subsystem was initially supported as a Linux System in Windows 10 RedStone 1 (RS1, 1607) Beta. Your options are as follows:

As of October 1, 2018 the most recent official Windows Build is Redstone 4. However, the Windows used to create this article is Redstone 3 (1709). The following guide is related to using SSH and the installation of the Linux Subsystem mentioned in point 3 above.

Installing the Linux Subsystem

  1. First, you’ll want to check your Version of Windows 10 and upgrade to a Version that supports the Linux Subsystem.
    Settings -> System -> About

  2. Once you’re updated, Run the ‘appwiz.cpl’ command from the Run dialog box (Windows Key + R) which will open up your ‘Programs and Features’.
    Open ‘Turn Windows features on or off’ which is located on the left side of the explorer window.
    Find ‘Windows Subsystem for Linux’ and install it.
  3. Restart the system to finish setting up the Linux Subsystem installation.
    Run the ‘bash’ command from the Run dialog box (Windows Key + R)

  4. As you can see, the subsystem package is not actually installed. You’ll need to visit https://aka.ms/wslstore to finish installing the package.

  5. We’ll focus on Ubuntu Linux in this article, but feel free to select your desired Linux flavor.
    Select Ubuntu to continue the installation.

  6. After installation is complete you’ll need to set a username and password. It does not have to be your Windows username.
    The user created here becomes the default administrator for Ubuntu and will be used for the sudo command.

  7. The installation of the Ubuntu Linux Subsystem of Windows 10 is now complete. From here on out, you can use Ubuntu as normal and install the necessary packages for general use.

SSH Server Installation and Operation

For this article, I am using Ubuntu version 18.04 LTS (Bionic Beaver). OpenSSH is installed during installation, but we still need to tweak some settings.

  1. Host Key Generation
    Using the ‘ssh-keygen -A’ command create a host key in the /etc/ssh path.

    test@DESKTOP-B38MLS1:/etc/ssh$ sudo /etc/init.d/ssh stop
    test@DESKTOP-B38MLS1:/etc/ssh$ sudo ssh-keygen -A
  2. sshd_config Settings
    By default, only public key authentication is allowed. Please refer to Xshell’s Help for public key authentication. We’re going to allow user passwords to continue with our connection for the sake of this article, but it is NOT recommended for security reasons. The following is the sshd_config setting required for this.
    test@DESKTOP-B38MLS1:/etc/ssh$ sudo vi /etc/ssh/sshd_config
    …
    # To disable tunneled clear text passwords, change to no here!
    PasswordAuthentication yes
    …
    test@DESKTOP-B38MLS1:/etc/ssh$ sudo /etc/init.d/ssh start

    You may see a message stating that the rsa key and ecdsa key were not created as host keys and were not able to be loaded. This message will not appear if you create and insert the key or if you change the settings in ssdh_config to not use these keys. This message will not affect your use of SSH.

Connecting from Xshell

For testing purposes, I am using Xshell 6 which is the latest version of Xshell available at the time of this article’s writing.

  1. Initialize the connection
    [C:\~]$ ssh localhost
    Host 'localhost' resolved to ::1.
    Connecting to ::1:22...
    Connection established.
    To escape to local shell, press 'Ctrl+Alt+]'.
    …
  2. Because this is the first connection attempt, you’ll be asked whether or not you want save the server’s host key information. Select ‘Accept Once’ or ‘Accept & Save’ to proceed.

  3. You’ll be prompted to enter your username and password. This is the username and password you created during the Ubuntu installation. Remember, the ‘Password’ field is enabled because we allowed password authentication when we were configuring the sshd_config above.

  4. You should see the following screen after login is completed.

  5. Note that the Windows file system is mounted in /mnt/c
    test@DESKTOP-B38MLS1:~$ df -h
    Filesystem Size Used Avail Use% Mounted on
    rootfs 40G 15G 25G 38% /
    none 40G 15G 25G 38% /dev
    none 40G 15G 25G 38% /run
    none 40G 15G 25G 38% /run/lock
    none 40G 15G 25G 38% /run/shm
    none 40G 15G 25G 38% /run/user
    C: 40G 15G 25G 38% /mnt/c
    test@DESKTOP-B38MLS1:~$

Quick Deployment Guide

  1. Update to at least Windows 10 Redstone 1
  2. Open ‘Programs and Features’ => Click ‘Turn Windows features on or off’ and install ‘Windows subsystem for Linux’
  3. Open your web browser and navigate to https://aka.ms/wslstore.
    Select Ubuntu to begin installation. A bash shell window will appear to complete the installation.
  4. Create a host key from in the bash shell. DO NOT enter a password.
    test@DESKTOP-B38MLS1:$ sudo ssh-keygen -t ed25519
    Generating public/private ed25519 key pair.
    Enter file in which to save the key (/root/.ssh/id_ed25519): 
    /etc/ssh/ssh_host_ed25519_key
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    …
  5. Configure /etc/sshd_config to accept Password Authentication (Optional)
    test@DESKTOP-B38MLS1:$ sudo vi /etc/ssh/sshd_config
    …
    # To disable tunneled clear text passwords, change to no here!
    PasswordAuthentication yes
  6. Initialize the SSH Server
    test@DESKTOP-B38MLS1:$ sudo /etc/init.d/ssh start
  7. Connect from Xshell
    [C:\~]$ ssh localhost
    
    Host 'localhost' resolved to ::1.
    Connecting to ::1:22...
    Connection established.
    To escape to local shell, press 'Ctrl+Alt+]'.
    …
    
    

Leave a Reply

17 + 2 =