SSH Server on Windows Server 2019

(OpenSSH)

1. Install the Server

PS C:\Users\Administrador> Add-WindowsCapability -Online -Name OpenSSH.Server
Path          :
Online        : True
RestartNeeded : False



PS C:\Users\Administrador> Set-Service sshd -StartupType Automatic
PS C:\Users\Administrador> Set-Service ssh-agent -StartupType Automatic
PS C:\Users\Administrador> Start-Service sshd
PS C:\Users\Administrador> Start-Service ssh-agent
PS C:\Users\Administrador> Get-Service sshd

2. Install the Client

PS C:\Users\Administrador> Add-WindowsCapability -Online -Name OpenSSH.Client


Path          :
Online        : True
RestartNeeded : False

3. Connect with Password

Now you can connect to the server

ssh user@ip

4. Configure pubkey authentication

  • If user is normal user: .ssh/authorized_keys in user home path
  • If user is admin user: %programdata%/ssh/administrator_authorized_keys

    Remove access of Everyone to the file, if not, pubkey authentication won’t be used.

    icacls authorized_keys /remove Everyone
    

    Set the config in C:\ProgramData\ssh\sshd_config

    PubkeyAuthentication yes
    

    Restart the service

PS C:\Users\USER\.ssh> Restart-Service sshd