Setup the Windows Subsystem for Linux Terminal

Cristea Bogdan Eugen
5 min readDec 26, 2020

Introduction

Windows operating system has introduced the ability to run Linux binary executables natively in August 2016. In the initial Windows Subsystem for Linux (WSL) release only Ubuntu image was available, but one year later several other Linux images were also supported. In June 2019 WSL 2 was announced with a Linux kernel running in a Virtual Machine (VM) backend based on a subset of Hyper-V features instead of using a system-call adaptation layer with no Linux kernel. WSL ensures near native system performance and is targeted toward developers and system administrators working on open-source projects or with remote Linux servers. While this is another step toward Linux integration with Windows, the WSL terminal setup on Windows is not as easy as in macOS or Linux, missing, until recently, the tabs support. The goal of this article is to explain the steps needed to setup WSL terminal with similar look and feel as in Linux or macOS.

Configuration Steps

1. Install WSL

WSL1 is available on Windows 10 and Windows Server 2019 while WSL2 is available only on recent Windows 10 versions. The steps below can be used for any WSL version, however in the following we will consider WSL2.

In order to enable WSL2 open PowerShell as administrator and enter this command

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

With WSL2 enabled, the next step is to enable the virtual machine needed to run the Linux kernel. This can be done also in PowerShell with administrator privileges:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

After this step a system reboot is needed.

After reboot download and install WSL2 using for example WSL2 Kernel update.

Next, you can search in Microsoft Store for your favourite Linux distribution. Note that it is not needed to have an account creared in Windows Store to install Linux. In the following I will use Ubuntu 20.04 LTS. When starting the first time Linux on Windows it might take a few minutes to start in order to install the required components. After installation you will be required to provide a UNIX username and password. The initial terminal window has no tabs, but otherwise it is similar to a Linux terminal where you can run almost any Linux command.

2. Install the New Terminal Application

You can replace the default WSL terminal using the new modern terminal application with tabs support. Search in Microsoft Store for "Windows Terminal", make sure that this is the application provided by Microsoft and install it. Again, you don't need to sign in in order to install this application.

When starting the first time the installed terminal application the default Power Shell terminal appears. By clicking the arrow button found in the title bar a dropdown menu is shown:

From this menu you can select Ubuntu terminal which will be opened in a new tab. You can make Ubuntu terminal the default terminal by clicking from the dropdown menu on Settings. If you don't have installed a suitable editor a dialog will be shown requesting to select an application to open the settings file. One possible option is to install Visual Studio Code. With the settings file open you must change the "defaultProfile" value with the GUID of "Ubuntu-20.04" profile found in "list" array under "profiles":

After this change, save the settings file and close it. You need to restart the Windows Terminal application in order to allow the new settings to be loaded and you should see that the default terminal is now Linux. When a new tab is created the same Linux terminal is used making the Windows Terminal application behave like the terminal found on Linux or macOS.

3. Install Zsh and Oh-My-Zsh

The default shell in Ubuntu terminal is bash. You can improve your experience using zsh with oh-my-zsh. First you must install zsh with:

sudo apt install zsh

then install oh-my-zsh. The installation script tries to setup zsh as your default shell, however this does not seem to work correctly so that you must explicitly change the default shell with:

chsh -s /bin/zsh

You must restart again the Windows Terminal for the changes to take effect. Now you should notice that the Linux prompt is changed and you can verify that the default shell is zsh with:

echo $SHELL

Further customizations can be made by editing .zshrc

vim ~/.zshrc

where the default theme can be changed or more plugins can be loaded (by default git plugin is loaded). An useful plugin is zsh-autosuggestions which provides suggestions as you type a command.

4. Configure Password-less Remote Login with Ssh

If you need to remotely login on other Unix machines with ssh without providing each time the user password you must copy your public ssh key on the remote machine and start the ssh-agent in the background in order to automatically provide your private ssh key for login.

In order to do so, first you must generate a pair of public and private ssh keys with:

ssh-keygen -t rsa -b 4096 -C “your_email@example.com”

Note that it is not mandatory to provide a password for your private ssh key, but, for improved security, you should always do so.

Next copy your public ssh key to the remote server:

ssh-copy-id "your_username"@"server address"

If you try to connect now with ssh on the remote server you will notice that the password you set for your private ssh key is required (if you set one when you generated the ssh keys). Instead of typing each time this password the ssh-agent can be enabled by editing .zshrc and pasting the lines below at the end of the file:

if [ -z “$(pgrep ssh-agent)” ]; then

rm -rf /tmp/ssh-*

eval $(ssh-agent -s) > /dev/null

ssh-add ~/.ssh/id_rsa

else

export SSH_AGENT_PID=$(pgrep ssh-agent)

export SSH_AUTH_SOCK=$(find /tmp/ssh-* -name “agent.*”)

fi

You must restart the Windows Terminal or open a new tab in order to reload .zshrc file. When you do so the password for your private ssh key is requested only once, then you can use ssh to login into the remote server without password. Opening other tabs will not require to input again your password as the ssh-agent is detected running in the background and the required environment variables are set.

Conclusions

In this article I have presented a setup for Windows terminal with tabs support using Linux and zsh. A method for enabling password-less remote access using ssh has been also presented. This setup allows to have a similar terminal experience as can be seen in Linux or macOS. Further customisations can install byobu in order to have a text-based window manager or other terminal based Linux applications.

--

--

Cristea Bogdan Eugen

I have an PhD degree in Networks and Telecommunications. I am working as Software Engineer and my interests lie in the area of network communication protocols.