Skip to content

Instantly share code, notes, and snippets.

@jarkkojs
Created December 13, 2022 04:25
Show Gist options
  • Save jarkkojs/9cd9300b10613cc32348b3e3d5acf1ab to your computer and use it in GitHub Desktop.
Save jarkkojs/9cd9300b10613cc32348b3e3d5acf1ab to your computer and use it in GitHub Desktop.
if ((Get-NetFirewallRule | Where-Object -Property DisplayName -eq 'wsl_ssh').count -eq 0)
{
Write-Output 'Creating ''wsl_ssh'' firewall rule'
New-NetFirewallRule -DisplayName wsl_ssh `
-Direction Inbound `
-Protocol TCP `
-LocalPort 10022 `
-Action Allow `
| Out-Null
}
# Remove forward to the old guest address first:
Remove-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\PortProxy\v4tov4\tcp' '*/10022' `
-ErrorAction SilentlyContinue
$guestAddress = (wsl hostname -i).split(" ")[0]
netsh interface portproxy add v4tov4 listenport=10022 connectport=22 connectaddress=$guestAddress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment