References:
- https://docs.microsoft.com/en-us/windows/wsl/install-win10
- https://docs.microsoft.com/en-us/windows/wsl/install-manual
- https://docs.microsoft.com/en-us/windows/wsl/user-support
- https://docs.microsoft.com/en-us/windows/wsl/wsl-config
Open Powershell in Administrator mode and enable WSL (Needs a computer restart):
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Download Ubutnu 16.04 (16.04 has been patched for over a year):
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.appx -UseBasicParsing
Open Powershell in Administrator mode and install the downloaded package:
Add-AppxPackage .\Ubuntu.appx
Now type the following in on the terminal:
ubuntu
# Installing, this may take a few minutes...
The first user account you create is automatically (https://aka.ms/wslusers) configured with a few special attributes:
- It is your default user -- it signs-in automatically on launch.
- It is Linux administrator (a member of the sudo group) by default. Type in a Linux username and password for the user.
NOTE: You will need this password to perform sudo
commands (dont loose it):
# Installation successful!
# Please create a default UNIX user account. The username does not need to match your Windows username.
# For more information visit: https://aka.ms/wslusers
# Enter new UNIX username:
ubuntu
# Enter new UNIX password:
password123
# Retype new UNIX password:
password123
# passwd: password updated successfully
# Default UNIX user set to: ubuntu
# To run a command as administrator (user "root"), use "sudo <command>".
# See "man sudo_root" for details.
You are now in an ubuntu session:
# ubuntu@windows10:~$
Having to enter a password when executing sudo commands is a pain so lets remove that.
Note that this is based on the default user being named ubuntu
.
sudo su
# [sudo] password for ubuntu:
cat<<EOF > /etc/sudoers.d/ubuntu && chmod 0440 /etc/sudoers.d/ubuntu
ubuntu ALL=(ALL) NOPASSWD:ALL
EOF
You can manage the Ubuntu instance from a Powershell session:
ubuntu.exe /?
# Launches or configures a linux distribution.
#
# Usage:
# <no args>
# - Launches the distro's default behavior. By default, this launches your default shell.
#
# run <command line>
# - Run the given command line in that distro, using the default configuration.
# - Everything after `run ` is passed to the linux LaunchProcess call.
#
# config [setting [value]]
# - Configure certain settings for this distro.
# - Settings are any of the following (by default)
# - `--default-user <username>`: Set the default user for this distro to <username>
#
# clean
# - Uninstalls the distro. The appx remains on your machine. This can be
# useful for "factory resetting" your instance. This removes the linux
# filesystem from the disk, but not the app from your PC, so you don't
# need to redownload the entire tar.gz again.
#
# help
# - Print this usage message.
You can also enter an ubuntu shell from other terminal emulators like Powershell
or cmd
by typing ubuntu
:
ubuntu
# root@windows10:~#
You can also change the default user if you want to change it from your previously created one:
ubuntu config --default-user ubuntu