Skip to content

ssh into WSL

Shun Git edited this page Sep 11, 2023 · 1 revision

setup SSH into a WSL

on host machine

run the below command in Windows PowerShell to create the file with the correct permissions

New-Item -Force -ItemType Directory -Path $env:USERPROFILE\.ssh;
Add-Content -Force -Path $env:USERPROFILE\.ssh\authorized_keys -Value '[publickey]';

comment out these lines in %PROGRAMDATA%/ssh/sshd_config (explanation)

#Match Group administrators  
#      AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

Open a Windows PowerShell as admin and setup OpenSSH

Set-Service -Name sshd -StartupType 'Automatic';
Start-Service sshd;

on client machine

change openssh-server port to 2222

add to .ssh/config

Host wsl-win
  HostName [host machine hostname]
  User [host windows username]

Host wsl
  ProxyJump wsl-win
  HostName localhost
  Port 2222
  User [wsl username]
Clone this wiki locally