Enable seamless connectivity: Using SSH on Windows 11 with Putty, Git Bash and WSL2 — Part 3

Thorsten Foltz
6 min readJan 21, 2024

--

In part one, I detailed the use of Putty, while part two focused on Git Bash, each having its own set of advantages and disadvantages. Now, let’s consider a scenario where you require more than just SSH and Git. Perhaps you need Python, including a Jupyter notebook, a virtual environment, or Docker. You desire a command-line interface (CLI) but prefer not to use PowerShell; you want the Linux experience.

In this final part, I’ll guide you through the installation of WSL2, a surprisingly straightforward process compared to Putty and Git Bash. Additionally, I’ll demonstrate how to create private and public keys, add the public key to GitHub, and clone a repository. Finally, I’ll walk you through installing Zsh, Oh My Zsh, and Docker within WSL2.

Microsoft’s Evolution: From Legal Battles to Collaboration with Linux and WSL Innovation

Microsoft and Linux? If you are a little bit older, you may recall the events of the late ’90s and early 2000s. The management in Redmond expressed concerns about Linux, which escalated to the point of legal disputes. The legal battles were primarily related to patent lawsuits and protection against third-party claims. These legal challenges were distinct from the earlier attempts to assert Windows NT’s superiority over Linux.

In today’s landscape, Microsoft’s stance has undergone a remarkable transformation. It is now a member of the Linux Foundation, a substantial portion of Azure servers operates on Linux, and Microsoft actively contributes to the Linux kernel. Perhaps the next logical step was the creation of the Windows Subsystem for Linux (WSL), which is open source and provided to customers, solidifying Microsoft’s commitment to seamlessly integrating Linux functionalities within the Windows environment.

Installation

Begin by verifying if “virtualization” is enabled. Access the task manager, click on “Performance,” and select “CPU.” If virtualization is not enabled, restart your computer, access UEFI, and enable virtualization. Subsequently, open PowerShell with administrative permissions and initiate the WSL installation:

PS C:\WINDOWS\system32> wsl --install

By default, Ubuntu will be installed. If you prefer another distribution, such as Debian, extend the installation command:

wsl --install -d Debian

The installation process should be swift, and after the customary reboot, you’ll have the ability to use a Linux distribution on your Windows system.

Usage

In my scenario, I opted for the installation of Ubuntu. Access it by clicking on “Ubuntu” in your start menu.

Ubuntu is now available on Windows 11

Once opened, allow a brief moment for initialization, and you’ll be prompted to enter a username. This username must not be the same used on your Windows system.

Only when opened for the first time
Now enter an user name
Welcome to Ubuntu on Windows 11

Your Windows file system is conveniently mounted in the “/mnt” directory, facilitating seamless file exchange between Windows and Ubuntu. To proceed, update the list of available packages and subsequently install them using the following commands:

sudo apt update && sudo apt upgrade -y

This ensures that you have the latest package information and updates for your Ubuntu installation.

Private and Public Keys

Now, you can again copy or, preferably, move the private and public keys you created in the first part into a folder named “.ssh,” which you’ll need to create. However, for the purpose of creating new keys using WSL execute the following command:

ssh-keygen -t rsa -o -b 4096 -C "wsl"

Allow me to repeat my brief explanation of the command:

  • ssh-keygen: Initiates the process of creating a private and corresponding public key.
  • -t rsa: Specifies the encryption algorithm, with RSA being a widely used and proven choice.
  • -o: Directs the tool to save the private key in the newer OpenSSH format, as opposed to the older PEM format.
  • -b 4096: Sets the key length to 4096 bits. The security increases with higher values, but performance may be impacted. A minimum of 2048 is recommended, and 4096 strikes a good balance between security and performance.
  • -C "wsl": Adds the comment "wsl" to help identify this specific key. You can customize the comment to your preference.
Creation of a private and public key

Usage

Your public key can now be shared, and it’s crucial to exercise caution here. While it’s safe to share your public key, never disclose your private key. Retrieve your public key using the following command:

cat ~/.ssh/id_rsa.pub

The “cat” command prints the content of the file “id_rsa.pub” into the terminal. The tilde (~) often serves as a shortcut to your personal home directory in many shells. For instance, in my case, it is equivalent to:

cat /home/thorsten/.ssh/id_rsa.pub
My public key printed into the terminal

Copy the key and share it with the server you intend to connect to, provide it to the responsible admin, or use it, for example, for GitHub.

Add your public key to GitHub

For the server connection demonstration, I once again utilized my virtual server on AWS:

ssh joe@3.71.202.104
Establish a connection
Established connection

Installing Zsh Shell

Bash serves as the default shell for Ubuntu, and while it’s robust, the experience can be enhanced with the Zsh shell. Particularly when combined with Oh-My-Zsh, it brings additional features. Begin by installing Zsh:

sudo apt install zsh

After the installation, you will be prompted for settings. Choosing option (2) is appropriate:

Choose Zsh config

Now install oh-my-zsh by

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Installation of oh-my-zsh
Successfully installed

Following a successful installation, you have the flexibility to choose from various themes and plugins. Edit your .zshrc file as illustrated above. In my instance, I replaced the default theme "robbyrussell" with "jispwoso."

Replace default theme with “jispwoso”

Among other appealing features (explore the oh-my-zsh repository for details), the Git integration is noteworthy. It displays the current branch and indicates if there are uncommitted changes with a marked symbol.

Docker Installation

Finally, let’s install Docker. To ensure you get the latest version, we will install it directly from the Docker official documentation. Copy the commands provided there to complete the installation. Firstly, set up docker repository.

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

Secondly, install the newest version:

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Last step, test it:

sudo docker run --rm hello-world
Successfully installed docker and tested by using hello-world image

Conclusion

Over the course of three parts, I’ve offered a swift introduction to SSH connections using various tools. Personally, I would recommend utilizing WSL2 on Windows 11, but the choice depends on your comfort level with the command line, Linux, and, more importantly, your specific needs.

Moreover, I demonstrated how to install Zsh, Oh-My-Zsh, and Docker — all of which are now ready for use. WSL2 stands out as a commendable approach from Microsoft, seamlessly amalgamating the realms of Windows and Linux.

--

--

Thorsten Foltz

Senior Data Engineer working in different countries. For any question feel free to contact me via Linkedin.