Since 2016 · 50,000+ customers · ★ 5.0 on Google Live chatWhatsAppTelegramOpen a ticket
Get started
Windows Server

How to Change the SSH Port on Windows Server (OpenSSH)

How to change the SSH port on Windows Server guide by 99RDP

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
Steps to change the OpenSSH port on Windows Server: edit sshd_config, open the firewall, restart sshd, test
Change the Windows SSH port

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.

Troubleshooting when SSH does not answer on the new port on Windows
Not connecting on the new port?

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.

How to connect to SSH on a custom port from different clients
Connecting to a custom port

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 no in sshd_config.
  • Limit who can log in with AllowUsers or AllowGroups.
  • 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.

Minakshi, Server Administrator L1 at 99RDP
Written byMinakshiServer Administrator L1, 99RDP. Part of the team that runs our servers and answers support.
Keep reading

More Windows Server guides

All Windows Server guides

Need a server for this?

✓ Setup in minutes✓ Full admin access✓ 7-day refund on new services