One place for hosting & domains

      Subsystem

      How To Install the Windows Subsystem for Linux 2 on Microsoft Windows 10


      Introduction

      The Windows Subsystem for Linux 2, WSL 2 or WSL for short, is a tool on Microsoft Windows 10 that allows developers to run a Linux environment directly on Windows without any modifications, secondary Virtual Machine software, or dual-boot setups. The WSL natively integrates with most applications on your workstation, allowing for a Linux-like development experience on Windows. The WSL accomplishes this by using Microsoft’s built in virtualization software called Hyper-V to run.

      In this tutorial you’ll enable the WSL, install Ubuntu 20.04 onto your workstation using the WSL, and install Microsoft’s new Windows Command Line to access your Ubuntu 20.04 installation. This will provide you with a Linux programming environment that is native to Windows.

      Prerequisites

      In order to follow along with this guide, you’ll need:

      • Personal Computer with Windows 10 installed: The Windows Subsystem for
        Linux 2 requires Windows 10 version 1903 or higher with build 18362 or higher. For ARM64 systems, version 2004 or higher with build 19041 is required. Builds lower than this will not support the WSL 2.

      Warning: If you are installing the WSL on a virtual machine you will need to expose CPU virtualizations flags to the virtual machine. For example, if you are installing the WSL on a virtualized Windows 10 that is running in Hyper-V named MyWSL you will need to run the following command on the virtualization host, not the virtual machine. This is a Windows command so you will need an elevated PowerShell prompt to do this. Replace MyWSL with the name of your VM in Hyper-V:

      • Set-VMProcessor -VMName MyWSL -ExposeVirtualizationExtensions $true

      If you are not installing the WSL on a virtual machine, you can skip this warning entirely.

      Step 1 — Enabling Windows Services for the WSL

      The first thing you need to do is enable specific Windows services so that you can run the WSL. These services come with Windows but are turned off by default until you decide you need them. Open up the Start menu and search for PowerShell. You’ll need to right click on PowerShell and click on Run as Administrator.

      Open Windows PowerShell as an administrator

      Once you’ve done this, a PowerShell window will open. You’ll use the Windows Deployment Image Servicing and Management tool to enable optional Windows features that are disabled by default. Run the following command to enable the WSL feature:

      PS C:Windowssystem32> dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
      

      Once you run the command you’ll see output similar to this:

      output

      Deployment Image Servicing and Management tool Version: 10.0.19041.844 Image Version: 10.0.19042.985 Enabling feature(s) [==========================100.0%==========================] The operation completed successfully.

      Next, run the following command in PowerShell to enable Windows’ Virtual Machine Platform. This enables the second generation of the WSL by enabling Hyper-V and allowing Windows’ to install Linux using it.

      PS C:Windowssystem32> dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
      

      Once you run the command you’ll see output similar to this:

      output

      Deployment Image Servicing and Management tool Version: 10.0.19041.844 Image Version: 10.0.19042.985 Enabling feature(s) [==========================100.0%==========================] The operation completed successfully.

      Once you have done this you will need to restart Windows for these changes to take place.

      After the restart is finished, log back in to your workstation.

      Next you’ll need to download the latest Linux kernel update package from Microsoft and install it.

      To install this package, click to download the wsl_update_x64.msi package to your local workstation. Once it is downloaded, run the application and follow the prompts to install it.

      Download the Linux Kernel patch and run

      Finally, you need to set the default version of the WSL to version 2. Open another PowerShell terminal as an administrator and run the following command:

      PS C:Windowssystem32> wsl --set-default-version 2
      

      Once you run the command you’ll see output similar to this:

      output

      For information on key differences with WSL 2 please visit https://aka.ms/wsl2

      Now that you’ve done this the WSL 2 is enabled and ready to run on your workstation. Next you’ll need to install a Linux-based operating system using the WSL 2.

      Step 2 — Installing Ubuntu 20.04 using the WSL

      Now that you have the WSL 2 installed, you next need to install a Linux distribution from the Microsoft Store. For this tutorial we will be installing the default Ubuntu option from the store, which happens to be Ubuntu 20.04 at this time. There are many different options to choose from and all should take a nearly identical approach to installation as laid out in this tutorial.

      Open your Start menu, search for the Microsoft Store, and open it.

      Open the Microsoft Store

      Locate the search bar in the upper right-hand corner and search for Linux.

      Search for Linux

      Many options will appear; select the Ubuntu tile to install the latest supported version of Ubuntu. Click the Get button to add the app to your account. Once you’ve done this, the Get button will be replaced by the Install button. Click that button to install Ubuntu to your local workstation. Once the installation is done a Launch button will appear. Click this to launch Ubuntu.

      Select Ubuntu and Install

      The first time you launch Ubuntu it will inform you that it is performing initial configuration that may take a few minutes. After this it will prompt you for a Linux system username and password. This username and password doesn’t have to be the same as your system but it will be required for you to be able to use sudo to gain admin privileges.

      Perform Initial Setup of Ubuntu

      Once you have created your user the initial setup is complete and Ubuntu is ready to be used.

      Once initial setup is done Ubuntu is ready to be used

      Now that you have Ubuntu installed, you’ll install a more robust terminal for accessing Ubuntu through Windows.

      Step 3 — Installing and Configuring the New Windows Command Line

      Ubuntu provides a default terminal for use, but Microsoft open sourced and reimplemented their Terminal tool and branded it at Windows Terminal. This terminal supports many more customization and ease-of-use options than the default Ubuntu terminal, so you’ll want to install it.

      Next you’ll install this terminal on your workstation. Navigate back to the search bar in the Microsoft Store and search for Terminal.

      Search Terminal in the Microsoft Store looking for Windows Terminal

      Install the Windows Terminal the same way you installed Ubuntu, by clicking Get and Install. Launch the terminal by clicking Launch or selecting the program from your Start menu.

      Get and Install the Windows Terminal. Then click launch

      By default, the Windows Terminal opens up a PowerShell console.

      Default Windows Terminal opens up PowerShell

      If you want to open a different console, click the down arrow button to see what is available. You have access to PowerShell, Command Prompt, and Azure Cloud Shell by default. When you install any WSL Linux, it will appear here as well like the Ubuntu install did. Clicking Ubuntu will open an Ubuntu shell in a new tab.

      Windows Terminal supports many different options

      If you want to change some of the Terminal’s default options, click the down arrow button and select Settings.

      Open up settings to change the default to the WSL Ubuntu

      Next, set Ubuntu as your default console. Under Default Profile select your Ubuntu WSL image, and click Save to make it your default option.

      Select Ubuntu as your Default Profile

      Now when you click the + button or open a new terminal Ubuntu will be the default shell.

      Clicking the plus or opening the terminal new will give you your WSL Ubuntu shell

      You now have the new Windows Command Line tool installed and configured to open your WSL Ubuntu terminal by default. You are now ready to use Linux on Windows using the WSL.

      Conclusion

      You now have a fully functioning Linux environment running in Windows. You configured your computer to take advantage of the Windows Subystem for Linux, and installed an Ubuntu environment using the WSL. If you prefer a different Linux distribution, there are others you can install, including Debian, SUSE, or Kali Linux. From here, you can install developer tools to have a complete Linux development environment running on Windows.



      Source link

      How To Create SSH Keys with OpenSSH on macOS, Linux, or Windows Subsystem for Linux


      Introduction

      When setting up a remote Linux server, you’ll need to decide upon a method for securely connecting to it. While passwords are one way of verifying a user’s identity, passwords have multiple vulnerabilities and can be cracked by a brute force attack. Secure Shell keys — better known as SSH keys — are often used instead of passwords, as they offer a more secure method of connecting to remote Linux servers. As part of the Secure Shell cryptographic network protocol, SSH keys also enable users to securely perform network services over an unsecured network, such as delivering text-based commands to a remote server or configuring its services.

      This tutorial will guide you through the steps of creating SSH keys with OpenSSH, a suite of open source SSH tools, on macOS and Linux, as well as on Windows through the use of the Windows Subsystem for Linux. It is written for an audience that is just getting started with the command line and will provide guidance on accessing the terminal on a personal computer. After completing this tutorial, you will have SSH keys that can be used to securely set up a server in the tutorial How To Set Up an Ubuntu 20.04 Server on a DigitalOcean Droplet that is part of the Introduction to the Cloud Curriculum (coming soon).

      If you are already familiar with the command line and looking for instructions on using SSH to connect to a remote server, please see our collection of tutorials on Setting Up SSH Keys for a range of Linux operating systems.

      Prerequisites

      To complete this tutorial, you will need:

      • A local machine running one of the following operating systems: macOS, Linux, or Windows with Windows Subsystem for Linux installed. If you are using Windows, you can find instructions for downloading or updating the Windows Subsystem for Linux on Microsoft’s documentation page. Note that while OpenSSH should work for a range of Linux distributions, this tutorial has been tested using Ubuntu 20.04.

      Note: If you are looking for instructions on how to create SSH keys on a Windows machine that does not have the Windows Subsystem for Linux, please visit our product documentation How to Create SSH Keys with PuTTY on Windows.

      • Some familiarity with working with a terminal and the command line. If you need an introduction to working with terminals and the command line, you can visit our guide A Linux Command Line Primer (coming soon).

      Step 1 — Understanding SSH Keys

      SSH keys are two long strings of characters that can be used to authenticate the identity of a user requesting access to a remote server. These keys are generated by the user on their local computer using a SSH utility. One key is private and stored on the user’s local machine. The other key is public and shared with the remote server or any other entity the user wishes to securely communicate with.

      When a user requests to connect to a server with SSH, the server sends a message encrypted with the public key that can only be decrypted by the associated private key. The user’s local machine then uses its private key to attempt to decrypt the message. If the message is successfully decrypted, the server grants the user access without the need of a password. Once authenticated, users can launch a remote shell session in their local terminal to deliver text-based commands to the remote server.

      In the next step, you will open a terminal on your computer so that you can access the SSH utility used to generate a pair of SSH keys.

      Step 2 — Opening a Terminal on Your Computer

      A terminal allows you to interact with your computer through text-based commands rather than a graphical user interface. The way you access the terminal on your computer will depend on what type of operating system you are using.

      On machines running macOS, the Terminal application is typically located in the Utilities folder inside the Applications folder. You can also find it by searching for “terminal” in the Search Spotlight.

      If you are working on a Linux computer, your distribution’s default terminal application is also typically located in the Utilities folder inside the Applications folder. You can also find it by searching for “terminal” with the Desktop search functionality.

      If you are working on a Windows machine running Windows Subsystem for Linux, a Linux terminal should open immediately after installation. You can also find it by searching for “Ubuntu” with the Desktop search functionality.

      Once you have located your system’s terminal application, open up a new terminal window. Your terminal should display your user name, a dollar sign ($), and a cursor. This is where you will begin to type commands to tell the terminal what to do.

      In the next step, you will enter a text-based command to generate a pair of SSH keys.

      Step 3 — Generating Keys With OpenSSH

      Your macOS or Linux operating system should have the standard OpenSSH suite of tools already installed. This suite of tools includes the utility ssh-keygen, which you will use to generate a pair of SSH keys.

      Type the following command into your terminal:

      You will then be prompted to select a location for the keys. By default, the keys are stored in the ~/.ssh directory with the filenames id_rsa for the private key and id_rsa.pub for the public key. Using the default locations allows your SSH client to automatically find your SSH keys when authenticating, so we recommend accepting these default options. To do so, press ENTER:

      Output

      Generating public/private rsa key pair. Enter file in which to save the key (/home/sammy/.ssh/id_rsa):

      Warning: If you have previously generated a key pair, you will be prompted to confirm that you actually want to overwrite the existing key:

      Output

      /home/sammy/.ssh/id_rsa already exists. Overwrite (y/n)?

      If you choose to overwrite the key on disk, you will not be able to authenticate using the previous key anymore. Selecting “yes” is an irreversible destructive process.

      If you’re certain that you want to overwrite the existing key on disk, you can do so by pressing Y and then ENTER.

      If you choose the default location, your public key will be located in /home/sammy/.ssh/id_rsa.pub and your private key will be located in /home/sammy/.ssh/id_rsa. Note that in your filepath, sammy will be replaced with your username.

      After selecting a location for the key, you’ll be prompted to enter an optional passphrase which encrypts the private key file on disk.

      If you enter a passphrase, you will have to provide it every time you use this key (unless you are running SSH agent software that stores the decrypted key). We recommend using a passphrase, but you can just press ENTER to bypass this prompt:

      Output

      Created directory '/home/sammy/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again:

      Following that final prompt, your system will generate the SSH key pair:

      Output

      Your identification has been saved in /home/sammy/.ssh/id_rsa. Your public key has been saved in /home/sammy/.ssh/id_rsa.pub. The key fingerprint is: a9:49:EX:AM:PL:E3:3e:a9:de:4e:77:11:58:b6:90:26 sammy@203.0.113.0 The key's randomart image is: +--[ RSA 2048]----+ | ..o | | E o= . | | o. o | | .. | | ..S | | o o. | | =o.+. | |. =++.. | |o=++. | +-----------------+

      You now have a public and private key that you can use to authenticate.

      Conclusion

      Congratulations, you have now generated a pair of SSH keys. These keys can be used to securely connect with a remote server and are necessary for the tutorial How To Set Up an Ubuntu 20.04 Server on a DigitalOcean Droplet that follows this tutorial in the Introduction to the Cloud Curriculum (coming soon).

      For a deeper dive on working using SSH, please visit our guide SSH Essentials: Working With SSH Servers, Clients, and Keys.



      Source link

      Trying the New WSL 2. It’s Fast! (Windows Subsystem for Linux)


      In this post, I cover some first impressions from my experience installing and running WSL2 (Windows Subsystem for Linux) in my dev workflow.

      I haven’t done any exhaustive, scientific, or precise tests by any means. What I have found though is that WSL is about 5 times faster for everyday web development tasks like npm or yarn.

      Also, hot reloading and working with create-react-app or the vue-cli is faster!

      Read on for installation, getting started, gotchas, and specific timing on npx create-react-app

      What does WSL 2 bring?

      This is the process I went through and the surprises I encountered while installing.

      Installing WSL2 on Windows 10

      Microsoft now has stable documentation on how to install WSL and update to WSL2.

      To get up and running, follow the guide above through to the point where you set up a new linux distribution.

      Checking if the Install Worked

      The following command will show us what distros we have installed and what version they are on:

      • wsl --list --verbose
      • # or shorthand
      • wsl -l -v

      Installation Failure

      If you already had Ubuntu installed on WSL 1, you may have to completely uninstall and reinstall it.

      If your computer is having trouble running the update command (like my computer), then you may want to completely uninstall and reinstall your distro.

      I went into the Windows settings under Apps > Apps and Features and uninstalled Ubuntu:

      Then I made sure that the default version I wanted for all new installs was version 2:

      • wsl --set-default-version 2

      Now we can go into the Windows Store to install it:

      Once we’re installed, then we can check to be sure that version 2 was installed. Open up Powershell and run:

      Running WSL

      You can open up Windows Terminal and use the Ubuntu dropdown:

      Alternatively you can open up either cmd or Powershell and run:

      • # open up windows subsystem for linux
      • wsl

      Gotchas with WSL 2

      Speed when transferring between file systems is a little slow right now. That’s not a worry for me since I never transferred. I worked solely inside of my Windows files which were mounted into the Linux system.

      Here’s a guide on User Experience changes from WSL 1 to WSL 2. The two big gotchas are:

      1. Move your files into the Linux file system instead of your Windows system
      2. You will need to access localhost apps like [localhost:3000](http://localhost:3000) via an IP address like 192.168.28.2:3000

      Move all files into Linux

      To take advantage of all the new speed improvements in WSL 2, our files will need to be moved into the Linux filesystem.

      The best way to figure out where to move your files is to find the home directory in Linux, then open it in Windows explorer. Run the following:

      • # find the home folder
      • cd ~
      • # open up windows explorer for this folder
      • explorer.exe .

      Notice the path as a Network path:

      We can now move our files from our Windows folders into this new networked folder. We’ll be able to access it from our WSL and interact with it as if it were still in the same Windows files.

      For instance, we can install Node using a tool like n and then run npm start to run a local server for let’s say a React app.

      Network Isn’t localhost Yet

      When we create an app using create-react-app or the vue-cli, we will usually run a command like yarn start or yarn serve to run a local server.

      Normally we would be able to check on our application right in our browser using [localhost:3000](http://localhost:3000) for React or [localhost:8080](http://localhost:8080) for Vue.

      In the early stages of WSL 2, we can’t use localhost. We need to use an IP since Linux is inside a VM.

      To access your application currently, we will use an IP.

      Notice the 192.168.28.2:3000. We’ll use that to access our application:

      A Quick Comparison and Speed Test

      This entire exercise was to get a setup that was faster than the previous one. Let’s see if this setup is any faster!

      I don’t have anything too scientific. I’ll go back and run more tests, but I was frustrated how long a new React app took WSL 1 to make.

      For now, our test will be to run npx create-react-app my-new-app.

      We’ll be comparing the following machines. I know this isn’t scientific at all. I wish I had more computers with similar setups. I wish I had done these speed tests before I upgraded to WSL 2. Oh well. We have what we have!

      • My desktop machine (super powerful, more than the laptops for sure)
      • Surface Book 2 15" i7
      • MacBook Pro 15" 2015
      • npx create-react-app my-new-app

      Here are the numbers I got from running the test a few times on each platform.

      • Surface Book 2 WSL 1: 257 seconds
      • Surface Book 2 WSL 2: 52 seconds
      • 2015 MacBook Pro: 45 seconds
      • 2018 MacBook Pro: 38 seconds

      While still not as fast as the latest MacBook Pro, WSL 2 has made significant improvements over WSL 1.

      What’s Next?

      We’ll keep getting updates and I’ll keep testing to see if performance is improving. I would love to get to a point where WSL 2 on Windows could be as fast as a 2018 MacBook Pro.

      I love both Windows and Mac platforms and with WSL 2, my tools on both platforms has gotten even closer:

      Happy coding!



      Source link