Fast way to setup OpenSSH on Windows Server (version below 2019)


Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString(''))
choco install openssh
cd "C:\Program Files\OpenSSH-Win64\"
sc.exe config sshd start=auto

Change default shell (I assume you need PowerShell 6):

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\PowerShell\6\pwsh.exe" -PropertyType String -Force

Generate keys for remote access:

  1. Login under proper user.
  2. Execute ssh-keygen.exe.
  3. Copy $Env:UserProfile\.ssh\id_rsa to external instrument (ssh client).
  4. Move or add $Env:UserProfile\.ssh\ to $Env:UserProfile\.ssh\authorized_keys.
  5. Fix authorized_keys permissions:
$acl = Get-Acl $Env:UserProfile\.ssh\authorized_keys
$usersid = New-Object System.Security.Principal.Ntaccount("Everyone")
$acl | Set-Acl $Env:UserProfile\.ssh\authorized_keys

For localized Windows: there’s no “Everyone”, but something in your language. Use GUI.

Debug (if things go wrong):

((New-Object System.Net.WebClient).DownloadFile('', 'C:\'))
Expand-Archive -LiteralPath 'C:\' -DestinationPath 'C:\pstools'
sc.exe stop sshd
C:\pstools\PsExec64.exe -s sshd.exe -d

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: