====== 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 Features[(https://www.bleepingcomputer.com/news/microsoft/heres-how-to-enable-the-built-in-windows-10-openssh-client/)]. You can run the OpenSSH Agent by enabling it in the system settings and use KeePassXC[()] or PuTTY Pageant to fill its keystore[(https://docs.microsoft.com/de-de/windows-server/administration/openssh/openssh_keymanagement)]. # 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.[(https://snowdrift.tech/cli/ssh/git/tutorials/2019/01/31/using-ssh-agent-git-windows.html)] [Environment]::SetEnvironmentVariable("GIT_SSH", "$((Get-Command ssh).Source)", [System.EnvironmentVariableTarget]::User) ==== Use OpenSSH Agent in WSL2 ==== To use the OpenSSH agent provided by the [[wsl|Linux Subsystem on Windows (WSL)]], e.g. to connect with your Ubuntu or Debian shell to remote hosts, you can use [[https://github.com/jstarks/npiperelay|npiperelay]]. In WSL2, you need to install ''socat'' and put the following in your ''.bashrc'' (if you use bash):[(https://code.mendhak.com/wsl2-keepassxc-ssh/#tell-wsl-to-use-it)] 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 ==== [[https://github.com/PowerShell/Win32-OpenSSH|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