OpenSSH is an essential tool for securely managing servers remotely. This guide explains how to install and configure OpenSSH on Windows Server 2022 to utilize the SSH service.
Windows Server: Install OpenSSH
- Overview
- Prerequisites
- Install OpenSSH for Windows
- Setup automatic SSHD startup
- Configure Firewall Rules for SSH Server
1. Overview
2. Prerequisites
Before you begin, ensure your computer meets the following requirements:
- A device with at least Windows Server 2019 or Windows 10 (build 1809).
- PowerShell 5.1 or later.
- An account that is a member of the built-in Administrators group.
3. Install OpenSSH for Windows
To install OpenSSH using PowerShell, run PowerShell as an Administrator.
powershell
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'The command should return the following output if neither are already installed:
powershell
Name : OpenSSH.Client~~~~0.0.1.0
State : NotPresent
Name : OpenSSH.Server~~~~0.0.1.0
State : NotPresentThen, install the server or client components as needed:
If you install OpenSSH Server, you (maybe) need to restart the system.
powershell
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0powershell
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0Both commands should return the following output:
powershell
Path :
Online : True
RestartNeeded : False4. Setup automatic SSHD startup
Setup SSH Service to start automatically with the System:
powershell
Set-Service sshd -StartupType Automatic
Start-service sshd 5. Configure Firewall Rules for SSH Server
powershell
#specificIPs = Managementserver (e.g.:IP,IP2)
$specificIPs = "172.XX.XX.XX"
# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -RemoteAddress $specificIPs
} else {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}