Setting up OpenSSH on Windows Server 2016

  • Download the latest --zip-- file from Github
    • Run script on server to download the file:
PS C:\> Invoke-WebRequest https://githu
b.com/PowerShell/Win32-OpenSSH/releases/download/v0.0.22.0/OpenSSH-Win64.zip -OutFile openssh.zip
  • Extract the files from the zip file:
PS C:\> Expand-Archive .\openssh.zip 'C:\Program Files\'
  • Update the Enviroment Path:
PS C:\> ($env:path).split(“;”)
PS C:\> $oldpath = (Get-ItemProperty -Path ‘Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment’ -Name PATH).path
PS C:\> $newpath = “$oldpath;C:\Program Files\OpenSSH-Win64\”
PS C:\> Set-ItemProperty -Path ‘Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment’ -Name PATH -Value $newPath
  • Can use the following command to create a temporary path:
$env:path+='c:this'
  • Restart Powershell / Server for changes to take effect.
  • Confirm that OpenSLL is listed within the enviroment path:
PS C:\> ($env:path).split(“;”)
  • Open Powershell and set the current directory to OpenSSL:
PS C:\> cd 'C:\Program Files\OpenSSH-Win64\'
  • Execute the --.\install-sshd.ps1-- script:
PS C:\Program Files\OpenSSL-Win64> .\install-sshd.ps1
  • Generate SSH host-key:
PS C:\Program Files\OpenSSL-Win64> .\ssh-keygen.exe -A
  • Start the SSHD service:
PS C:\> Start-Service -Name sshd
  • Set the service to start on boot:
PS C:\> Set-Service -Name "sshd" -StartupType automatic
PS C:\> Get-WMIObject win32_service -Filter "name = 'sshd'"
PS C:\> Get-WMIObject win32_service | Format-Table Name, StartMode -auto
  • Open up the Firewall port for SSH:
PS C:\> netsh advfirewall firewall add rule name="Open Port 22" dir=in action=allow protocol=TCP localport=22

References

Author image
IT guy trying to break the IT stereotype, whilst being addicted to IT stereotypical things.