Using the Linux Subsystem (WSL) in Windows 10

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:

  • Connect by installing a 3rd party SSH server for Windows

  • Installing Windows 10’s SSH Proxy and Connecting to the CMD Console

  • Connect after installing the Linux Subsystem of Windows 10

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 a CMD console

     

  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.


    The following dialog may appear, but it is not mandatory. You can simply close this dialog to continue.

     


    The download process may take a significant amount of time. After its completes, you can install the Ubuntu package by clicking the Launch button.

     

     

  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.

     

    As you can see, the latest build 20.04 at Jun 18 2021 was successfully installed

     

  7. The installation of the Ubuntu Linux Subsystem of Windows 10 (As of June 21, 2021, the most recent version is 20.04) 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.

    root@DESKTOP-49DPI98:/home/test# ssh-keygen -A ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519 root@DESKTOP-49DPI98:/home/test# /etc/init.d/ssh start * Starting OpenBSD Secure Shell server sshd [ OK ] root@DESKTOP-49DPI98:/home/test#


    Depending on your Windows Defender Firewall, a Windows Security Alert dialog may popup. You must click the Allow access button to establish SSH connections.

     

  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 restart




    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.

    1. 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.

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

  4. Note that the Windows file system is mounted in /mnt/c

 

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.



  5. Configure /etc/sshd_config to accept Password Authentication (Optional)



  6. Initialize the SSH Server



  7. Connect from Xshell