
Windows Server includes the OpenSSH server, which listens on port 22 by default. Moving it to another port cuts down the automated login attempts that scan port 22. This guide shows how to install OpenSSH if needed, change the port in sshd_config, open the new port in Windows Firewall, and test it, without locking yourself out. It works on Windows Server 2019, 2022 and 2025 (and Windows 10/11).
Quick answer(PowerShell as Administrator):
New-NetFirewallRule -Name sshd-2222 -DisplayName "OpenSSH (2222)" -Direction Inbound -Protocol TCP -LocalPort 2222 -Action Allow
(Get-Content C:\ProgramData\ssh\sshd_config) -replace '^#?Port\s+\d+','Port 2222' | Set-Content C:\ProgramData\ssh\sshd_config
Restart-Service sshd
ssh -p 2222 Administrator@your-server
Step 1: Make sure the OpenSSH server is installed
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'
If the state is NotPresent, install and start it:
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType Automatic
Step 2: Open the new port in Windows Firewall first
Add the firewall rule before changing the port, so you can't lock yourself out of a remote server:
New-NetFirewallRule -Name sshd-2222 -DisplayName "OpenSSH Server (2222)" `
-Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 2222
Choose any free port between 1024 and 65535. If your provider or router has its own firewall, open the port there too.
Step 3: Change the port in sshd_config
The configuration file is C:\ProgramData\ssh\sshd_config (the ProgramData folder is hidden). Open it as Administrator:
notepad C:\ProgramData\ssh\sshd_config
Find the line #Port 22, remove the # and change the number:
Port 2222
Save the file. To listen on both ports during the switch, add two lines (Port 22 and Port 2222) and remove the old one once the new port works.
Step 4: Restart the SSH service
Restart-Service sshd
Get-NetTCPConnection -LocalPort 2222 -State Listen
If the service doesn't start, check the configuration for typos: run sshd -t from C:\Windows\System32\OpenSSH\ to test it, and look in Event Viewer under Applications and Services Logs → OpenSSH → Operational.
Step 5: Test the new port
From another computer, keeping your current session open:
ssh -p 2222 Administrator@203.0.113.10
Test-NetConnection 203.0.113.10 -Port 2222
Once it works, disable the old rule for port 22 if you no longer need it:
Disable-NetFirewallRule -Name OpenSSH-Server-In-TCP
Remember the new port for tools like WinSCP, scp (scp -P 2222 ...) and SFTP clients.
More ways to secure SSH on Windows
- Use SSH keys instead of passwords. For administrators, keys go in
C:\ProgramData\ssh\administrators_authorized_keys. - Then set
PasswordAuthentication noinsshd_config. - Limit who can log in with
AllowUsersorAllowGroups. - Restrict the firewall rule to your own IP addresses with
-RemoteAddress.
Frequently asked questions
Where is sshd_config on Windows?
In C:\ProgramData\ssh\sshd_config. The ProgramData folder is hidden, so type the path directly.
What is the default SSH port on Windows?
Port 22, the same as on Linux. The built-in firewall rule OpenSSH-Server-In-TCP opens it.
Why can't I connect after changing the SSH port?
Usually the firewall blocks the new port, or the service didn't restart because of a typo. Check the firewall rule, run sshd -t, and restart sshd.
Does changing the SSH port make the server secure?
It reduces noise from automated scans, but it isn't real protection. Use key-based logins and firewall restrictions as well.


