CH-J Toolsserver management over SSH
Menu
All guides and articles →

Set up OpenSSH on Windows Server 2022 and 2025

Check the Windows feature, start SSH, restrict network access and verify the host key before connecting.

What does a working Windows SSH setup require?

You want to administer a Windows Server 2022 or 2025 machine from an SSH client, but installing a component alone does not establish usable access. The server needs a running listener, a permitted network path, a verified identity and an account that can authenticate. A successful ping proves none of these, and an open TCP port does not prove that you reached the right server.

This guide uses the OpenSSH component supplied with Windows, its default TCP port 22 and PowerShell run as administrator on the target server. Client examples also use PowerShell on Windows unless stated otherwise. Replace server.example with your server name and user with the intended Windows account. The subnet 192.0.2.0/24 is reserved for documentation; replace it with your real administration network.

Before making changes, decide which accounts need access and which client network they will use. Write down the recovery method and the expected server name. This gives you a concrete acceptance test: a permitted administrator can reach the expected machine, verify its identity and sign in, while an unrelated network does not gain access through an overlooked rule.

Why can SSH be unavailable even when the client is installed?

The client executable ssh.exe starts outgoing connections. The server service sshd accepts incoming ones. Having the client does not establish that the server capability is installed or that its service is running. Windows Server 2025 includes OpenSSH by default; on Server 2022, check the optional capability and install it if absent. Inspect the actual machine rather than assuming an image has standard defaults.

Get-WindowsCapability -Online -Name 'OpenSSH.Server~~~~0.0.1.0'
Get-Service -Name sshd -ErrorAction SilentlyContinue
Get-NetTCPConnection -State Listen -LocalPort 22 -ErrorAction SilentlyContinue

Read these results separately. The capability state answers the installation question, the service status answers whether sshd runs, and a listening socket answers whether something accepts local connections on port 22. If a listener exists, check its OwningProcess with Get-Process -Id before assuming it belongs to OpenSSH. No listener means you should investigate locally before changing a router or client.

How do you install and start the server safely?

Keep a working console or another tested recovery path. Installing OpenSSH can create an enabled inbound firewall rule. Perform the initial setup on an isolated administration network or behind an existing network restriction, then check and scope the rule before exposing the server.

  1. Open an elevated PowerShell session on the target server and check the capability state.
  2. Install only a missing capability. If installation fails, stop and inspect the error and your approved Windows Update or Features on Demand source policy.
  3. Start sshd, configure automatic startup and confirm that the service reports Running.
$cap = Get-WindowsCapability -Online -Name 'OpenSSH.Server~~~~0.0.1.0' -ErrorAction Stop
if ($cap.State -ne 'Installed') {
    Add-WindowsCapability -Online -Name 'OpenSSH.Server~~~~0.0.1.0' -ErrorAction Stop
}
Start-Service -Name sshd -ErrorAction Stop
Set-Service -Name sshd -StartupType Automatic -ErrorAction Stop
Get-Service -Name sshd

If servicing reports that a restart is required, schedule it through your normal maintenance process and repeat the checks afterwards. Do not remove and reinstall OpenSSH simply because remote access fails. A stopped service, a firewall restriction and rejected credentials require different fixes; reinstalling obscures the original evidence.

How do you restrict port 22 to the administration network?

First confirm which source address the server sees, especially when you connect through a VPN, NAT or a jump host. Use that address or subnet for the remote scope. Run the following on the server only after replacing the documentation subnet. Inspect the existing rule before changing it; the example normalizes the named rule to inbound TCP port 22.

$AdminSubnet = '192.0.2.0/24'
$rule = Get-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -ErrorAction SilentlyContinue
if ($rule) {
    $rule | Format-List Name, Enabled, Direction, Action, Profile
    $rule | Get-NetFirewallPortFilter
    $rule | Get-NetFirewallAddressFilter
    $rule | Set-NetFirewallRule -Enabled True -Direction Inbound -Action Allow -Protocol TCP -LocalPort 22 -RemoteAddress $AdminSubnet -ErrorAction Stop
} else {
    New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -RemoteAddress $AdminSubnet -ErrorAction Stop
}
Get-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' | Get-NetFirewallAddressFilter

Scoping one rule does not cancel other rules that allow the same traffic. Review the effective inbound rules, active network profile and centrally managed policy for additional broad allowances. If Group Policy controls the rule, make the restriction in the responsible policy rather than repeatedly applying a local edit. Check upstream firewalls separately; a Windows rule cannot open a blocked VPN or network firewall path.

After the positive connection test, check the restriction from an approved test machine outside the allowed range, if your environment permits that test. It should not establish TCP access through this rule. Record both results together with the source addresses. Testing only from your own workstation can confirm connectivity while missing an unintended broad allowance elsewhere in the effective policy.

How do you verify the server before signing in?

Host keys identify the server; user keys identify an account. On the server console, obtain the fingerprint of the public host key. Starting sshd for the first time normally creates its host keys under C:\ProgramData\ssh. This command reads a public file and does not regenerate the server identity.

ssh-keygen -lf "$env:ProgramData\ssh\ssh_host_ed25519_key.pub" -E sha256

Obtain that value through the console or another trusted administrative channel. On the client, connect using the intended account. The -l option keeps the login name separate from the host name and also accommodates a quoted domain-qualified account when needed.

ssh -l user server.example

Compare the entire SHA256 fingerprint and the key type with the console value before accepting the first connection. If the client offers another key type, obtain that key type from the console instead. An existing host key mismatch needs independent investigation, even after maintenance. A reachable port or an expected DNS name is not a substitute for this check.

Where do you put user keys on Windows?

For a new key on a Windows client, choose a dedicated filename and protect it with a passphrase. The guard below stops if either file already exists. Keep the private file on the client; transfer only the .pub file to the server through an authenticated channel.

$keyPath = "$env:USERPROFILE\.ssh\windows_server_admin"
if ((Test-Path -LiteralPath $keyPath) -or (Test-Path -LiteralPath "$keyPath.pub")) {
    throw "Choose a new key filename; existing files must not be overwritten."
}
New-Item -ItemType Directory -Path "$env:USERPROFILE\.ssh" -Force | Out-Null
ssh-keygen -t ed25519 -f $keyPath
  1. Check the target account and the effective AuthorizedKeysFile settings, including any Match block in C:\ProgramData\ssh\sshd_config.
  2. For a standard user with the default configuration, create .ssh in that account's actual profile and append the complete public key as one line to authorized_keys. Preserve existing keys and avoid an accidental .txt extension.
  3. For an administrator with the default administrator Match rule, append the public key to C:\ProgramData\ssh\administrators_authorized_keys instead. Treat this as a shared administrator authorization file.
  4. Inspect permissions before testing. Protect a standard user's key file from modification by other ordinary users. For the administrator file, follow Microsoft's ACL requirements: only SYSTEM and the built-in Administrators group, with SYSTEM granted full control.
icacls.exe "$env:ProgramData\ssh\administrators_authorized_keys"

The last command only displays ACLs. Back up an existing authorization file before editing it. Remove inappropriate inherited or explicit entries through your approved ACL procedure; adding the correct entries alone does not remove unwanted access. Built-in group names can be localized, so do not paste English account names blindly into permission changes.

How do you verify access and locate a failure?

Test from a different Windows machine inside the allowed network. TcpTestSucceeded should be True, but that result only confirms TCP connectivity. Run the SSH test afterwards, keeping the console available.

Test-NetConnection -ComputerName server.example -Port 22
ssh -v -o PreferredAuthentications=publickey -o PasswordAuthentication=no -i "$env:USERPROFILE\.ssh\windows_server_admin" -l user server.example

This login test requests public key authentication without falling back to an account password. A private key passphrase prompt is still normal. Once connected, run whoami and hostname, then exit and repeat the connection in a fresh session. Confirm that both the account and machine are the ones you intended to administer.

  • A timeout suggests checking DNS, routing, VPN and firewall scope. Compare the destination and source addresses with the intended network path.
  • Connection refused suggests checking whether the expected listener is running on that address and port; an actively rejecting firewall can also cause it.
  • Permission denied means you reached authentication. Check the account name, offered public key, selected authorization file, ACLs and any access restrictions in sshd_config.

On the server, inspect recent OpenSSH operational events and correlate them with your test. Read the actual message before changing permissions or authentication settings. Verbose client logs can contain account names and network details; redact them before sharing.

Get-WinEvent -LogName 'OpenSSH/Operational' -MaxEvents 20 | Select-Object TimeCreated, Id, Message

Change one variable at a time during diagnosis. Keep the server name, account and key fixed while comparing results from the same client. If you change the firewall, username and key file together, a successful retry will not tell you which correction mattered. Keep a short record of the observed error and the server event associated with each attempt.

Which shortcuts can expose the server or lock you out?

  • Do not disable Windows Firewall to diagnose SSH. Use listener checks, a scoped rule and a test from the permitted network.
  • Do not grant Everyone full control over key files to make authentication work. Fix the account, file location and ACLs that the server actually uses.
  • Do not disable host key checking or delete all saved host identities because one server changed. Verify that server independently first.
  • Do not copy Linux-only instructions such as chmod, systemctl or PermitRootLogin into this Windows setup. Windows service management, account rules and ACLs need Windows-specific procedures.

Changing firewall scope, account allow lists or password authentication can prevent your next login. Keep console access and verify each change with a separate new connection before ending your maintenance session.

How do you keep the configuration reliable?

Record the approved administration subnet, allowed accounts, host fingerprints and key owners. Remove public keys when access ends, review firewall policy after network changes and keep the Windows component serviced through your normal update process. Test automatic startup after a planned reboot instead of discovering a stopped service during an incident.

If policy requires key-only access, first prove it works for every required account and retain a recovery path. Back up C:\ProgramData\ssh\sshd_config to a separate, uniquely named file. Edit existing global settings before the first Match block rather than appending duplicate directives at the end. The intended global settings are:

PubkeyAuthentication yes
PasswordAuthentication no

Validate with the Windows-supplied executable before restarting. A successful syntax check normally produces no output; it does not prove that a particular user can sign in. After restarting, repeat the fresh public key login test. If it fails, use the console to restore the backup, validate and restart again.

& "$env:WINDIR\System32\OpenSSH\sshd.exe" -t
if ($LASTEXITCODE -ne 0) {
    throw "Configuration validation failed; do not restart sshd."
}
Restart-Service -Name sshd -ErrorAction Stop
Get-Service -Name sshd

How does CH-J Tools fit this Windows setup?

CH-J Tools supports selected Windows tools. Its Linux Disk Manager and NGINX workflows remain Linux workflows; setting up OpenSSH on a Windows server does not make those features available for Windows.

Frequently asked questions

Does Windows Server 2025 need OpenSSH installed separately?

OpenSSH is included by default. Check the capability, sshd service and firewall on the actual server; inclusion does not prove that your administration network can connect.

Why is my administrator authorized_keys file ignored?

The default administrator Match rule selects C:\ProgramData\ssh\administrators_authorized_keys instead of the profile file. Check the actual configuration and the shared file ACLs.

Do I need ssh-agent running on the server?

Not to accept incoming SSH connections. That is the job of sshd. An agent helps a client use private keys and does not repair server authorization files.

Why do I get Command Prompt instead of PowerShell over SSH?

The initial Windows OpenSSH default shell is cmd.exe. Start powershell.exe within the session if needed; changing the server default shell is a separate configuration task.

Does a successful port 22 test prove that SSH login works?

No. It confirms only a TCP connection. You still need to verify the host key, authenticate with the intended account and test the resulting session.

Detailed documentation

Microsoft: OpenSSH Server →

Microsoft: OpenSSH keys →

Microsoft: OpenSSH Server configuration →

Microsoft: Set-NetFirewallRule →

Microsoft: Get-NetTCPConnection →

OpenSSH: sshd (configuration validation) →

Biometric unlock and security →

All tutorials by category →