Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Herz3h/37561cd9d6ff20f1d21c984dad42ffe0 to your computer and use it in GitHub Desktop.
Save Herz3h/37561cd9d6ff20f1d21c984dad42ffe0 to your computer and use it in GitHub Desktop.
Enable WSL and Ubuntu 16.04 on Windows 10

Enable WSL and Ubuntu 16.04 on Windows 10

References:

Install and setup

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

Setup your default user

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

Managing distro

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment