Page content

Windows Setup for SSH

Objective

Problem Statement

I have a windows laptop (multiple) and I want to SSH into them for various reasons. I don’t need it to be accessible outside of my house (not for the purpose of this). I just find myself sometimes wanting to get or put some information from my Window machine while I am at work. Sometimes I also want to do the opposite, and SSH from my windows machine to my work laptop. So, how do I setup my windows machine where I could do such things? I want to SSH to and from my windows machine. On the face, this seems normal and straightforward. I have been at companies where we were a Windows shop, and no one used SSH, it was all RDP. I can hear everyone saying “why not just RDP into that machine”. The simple answer is because I don’t want all visual things. I don’t need that overhead of getting a GUI on my Mac or other Windows machine just to RDP and see the same setup in some cases. I also live in the terminal as many of us do, so it just would be easier if I just SSH and opened a file or SCP something. There really is a thousand things I can think of that would be great for this, and I am sure you can think of your own setup as well. Once we talk about doing an SSH from or to Windows, we run into some issues. Not all Windows machines are initially setup to make or receive SSH. Then once you are, how do you identify the environment you are in on the Windows machine (things work differently in Bash than in ZSH or Powershell). Lastly, how would I optionally make the environments the same. This last one may be controversial as its all preference.

Statement

  • SSH Into Window Laptop
  • SSH From Windows Laptop
  • ID Environment when SSH into Windows Laptop
  • Make the Environment the same on the Windows Laptop

Hurdles

  1. Prep the Windows Laptop 1.1 Install SSH Server 1.2 Install WSL2 1.3 Install SSH on WSL2 1.4 Install NeoVim on WSL2 1.5 Get SSH Key Pair (possibly to go both ways) 1.6 Test SSH Connection 1.7 Set Windows Default shell 1.8 Download ZSH on Windows
  2. SSH
  3. Determine what shell prompt you are in

Initial Setup

First Hurdle

First is to determine what shell or terminal you are in. This sounds like a silly thing, especially for non-windows users…I am sorry you have to sit through this.
As a side rant…windows has only had 1 terminal emulator for years, unless you did some fancy stuff and compiled your own. And its been decent for years, and its been the only way. And for decades Windows has ony had their verion of a shell, they call command shell. Now, that has all changed greatly, with WSL, MS Powertools, Alacritty, Kitty, Wezterm, ZSH, Powershell, and more. This is great for devs, but can also be confusing. The big thing is, we also want to solve this without a GUI…for reasons. Actually, its one thing to say and know what terminal you have open, that should be easy, visually. But its the shell and how to determine that.
Why? Well…Powershell has different commands for doing this stuff than Bash, which is different than Command Shell, which is different than Powershell, and so on. Plus, WSL will have a different default shell than the Powershell ISE which is different than the trusty old command prompt and so on. This is important as they are vastly different, and it will alter the commands you are looking for.

STEPS

Prep the Windows Laptop

Install SSH Server

this is just for windows in general stop here if you want to ssh into the windows cmd or powershell environments only

Install WSL2

Install SSH on WSL2

configure ssh access on wsl sudo apt install openssh-server sudo sed -i -E … sudo service ssh restart allow default wsl user to start the ssh server w/o pw sudo sh -c “echo ‘$USER ALL=Root NOPASSWD: /usr/sbin/service ssh start’ >/etc/sudoers.d/service-ssh-start”

Install NeoVim on WSL2

this changes based on what WSL environment you have setup. YOu could do a brew install neovim or sudo pacman neovim or sudo apt-get install newovim or sudo apt install neovim or sudo apk add newovim or …you get the idea…

For windows cmd prompt or powershell run one of the following based on your preference for installer… winget install Neovim.Neovim choco install neovim scoop bucket add main && scoop install newovim I personally try to use winget for this.

With winget or brew make sure to update and upgrade everything first… brew update brew upgrade winget upgrade –all

on Windows you will need to add the nvim to the PATH variable in powershell, assuming you are not going to wsl or switching shells $env:PATH += “;C:\NvimLocation”

Also on Windows, you can setup to auto-login to WSL which is great for keeping environments consistent.
OR you can create this create script for determining what prompt you are in, and then creating a shortcut to see what is going on in your various shells (so it will work in any shell) echo %PATH%

In Windows to adjust the default shell you have to run this powershell command. New-ItemProperty -Path “HKLM:\SOFTWARE\OpenSSH” -Name DefaultShell -Value “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” -PropertyType String -Force Adjust based on the shell you want.
Remember in windows they use forwared slash () but that is also an escape character so you have to do double forward slash when in any terminal.
Then restart the service for ssh. Also, very often in windows all paths and directories may contain spaces so they should always be wrapped in quotes This will also change it for when you are physically on the machine something to think about.

Get SSH Key Pair (possibly to go both ways)

Test SSH Connection

Set Windows Default shell

Download ZSH on Windows

SSH

Determine what shell prompt you are in