Table of Contents

SSH in Microsoft® Windows™

Shells

Recommended is the msys2 shell, installable through chocolatey. If you want to transfer files with a GUI, you can use WinSCP. Don't use PuTTY, it's old and slow. If you absolutely must use a GUI tool, KiTTY is the better alternative.

OpenSSH

Client

The OpenSSH client is installed by default since 2018. For earlier versions of Windows, you can enable it in the Windows Features1.

You can run the OpenSSH Agent by enabling it in the system settings and use KeePassXC2 or PuTTY Pageant to fill its keystore3.

# By default the ssh-agent service is disabled. Make sure you're running as an Administrator.
Get-Service ssh-agent | Set-Service -StartupType Automatic
 
# This should return a status of Running
Get-Service ssh-agent
 
# Now load your key files into ssh-agent
ssh-add ~\.ssh\id_ed25519

Use OpenSSH Agent in Git for Windows

The environment variables have to be set properly.4

[Environment]::SetEnvironmentVariable("GIT_SSH", "$((Get-Command ssh).Source)", [System.EnvironmentVariableTarget]::User)

Use OpenSSH Agent in WSL2

To use the OpenSSH agent provided by the Linux Subsystem on Windows (WSL), e.g. to connect with your Ubuntu or Debian shell to remote hosts, you can use npiperelay.

In WSL2, you need to install socat and put the following in your .bashrc (if you use bash):5

.bashrc
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
 
ss -a | grep -q $SSH_AUTH_SOCK
if [ $? -ne 0 ]; then
    rm -f $SSH_AUTH_SOCK
    (setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"$HOME/winhome/go/bin/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &) >/dev/null 2>&1
fi

This assumes you have a symlink from ~/winhome to your Windows home directory (usually in /mnt/c/Users/).

Server

OpenSSH server is available for Windows and you can even use PowerShell through it.

# Set the sshd service to be started automatically
Get-Service -Name sshd | Set-Service -StartupType Automatic
 
# Now start the sshd service
Start-Service sshd