Skip to content

Accepting SSH on port 443 as well: Ubuntu 24.04 and Windows OpenSSH setup

Interactive Diagram

새 탭 ↗

Some networks block outbound port 22 and leave only 443, the web port, open. Run ssh against a remote VM from such a network and it waits for a long time, then times out. If the server’s SSH daemon (sshd) accepts 443 alongside 22, you can reach the same server on 443.

This article keeps port 22 and adds 443. It first checks whether port 22 is really what’s blocked, then walks through the setup on Ubuntu 24.04 and on Windows OpenSSH Server, and finishes with the client’s ssh_config. Commands and behavior follow the OpenSSH, Ubuntu, and Microsoft documentation as of 2026-11-17.

Running coding agents on a remote VM and attaching over SSH is covered in the Herdr and Windows over SSH article. This one covers the SSH connection underneath.

You are giving sshd a second door. The existing door on 22 stays, and a new one opens on 443. Opening the door isn’t enough on its own: the server firewall and the network rules in front of the server also have to let 443 through.

WhereWhat to doUbuntu 24.04Windows
sshd configAdd Port 443Drop-in in /etc/ssh/sshd_config.d/Top of %ProgramData%\ssh\sshd_config
Apply the configRefresh listening portsdaemon-reload, restart ssh.socketRestart the sshd service
Server firewallAllow inbound 443ufwWindows Defender Firewall rule
Network in front of the serverAllow inbound 443Cloud security group, router, and so onSame
ClientSpecify the portssh -p 443 or ~/.ssh/configSame

These are the errors you usually see when port 22 is blocked.

kex_exchange_identification: read: Operation timed out
banner exchange: Connection to my-vm.example.com port 22: Operation timed out

Once the TCP connection is up, an SSH server speaks first and sends its version string (the banner). This error means the banner never arrived after the TCP connection. Connect to port 22 with nc and wait a few seconds to see whether a banner shows up.

Terminal window
nc -v my-vm.example.com 22

A healthy server prints a line such as SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.20 right away. Read the result like this.

ResultMeaning
Banner appears right awayThe network is fine. Look at authentication or client settings
The connection itself times outPackets don’t reach the server. Look at firewalls and network rules
Connects, but no bannerA device in the middle accepts the connection without passing SSH through, or the server’s sshd can’t respond
Connection refusedThe packet reached the server, but nothing listens on that port

Trying a port the server doesn’t use helps spot a device in the middle. If even an unused port connects, something between you and the server is accepting the connection.

Terminal window
nc -vz -w 5 my-vm.example.com 12345

Also try from a different network, such as a phone hotspot. If the banner arrives right away there, the server is fine and the network you normally use is blocking port 22.

Keep one existing SSH session open while you change the settings. If something goes wrong, you can roll back from that session.

Terminal window
sudo ss -tlnp | grep ':443 '

This should print nothing. If a web server such as nginx already uses 443, this approach won’t work.

Ubuntu’s default /etc/ssh/sshd_config reads the sshd_config.d directory at the very top. Check that line and the current Port settings first.

Terminal window
grep -n '^Include\|^Port' /etc/ssh/sshd_config

If Include /etc/ssh/sshd_config.d/*.conf is there, put the ports in a separate file.

Terminal window
printf 'Port 22\nPort 443\n' | sudo tee /etc/ssh/sshd_config.d/10-ports.conf
sudo sshd -t && echo CONFIG_OK

Port can appear more than once, and sshd listens on every port listed. Once you list any Port, though, the default 22 is no longer added for you, so include Port 22 as well. If the main file already has an uncommented Port 22, put only Port 443 in the drop-in.

Since Ubuntu 22.10, OpenSSH runs with systemd socket activation. Port 22 is held by systemd’s ssh.socket, not by sshd, and sshd starts when a connection arrives. On Ubuntu 24.04, a systemd generator reads the port and address settings from sshd_config to build the socket configuration. That’s why restarting only the ssh service doesn’t open the new port.

Terminal window
if systemctl is-active --quiet ssh.socket; then
sudo systemctl daemon-reload
sudo systemctl restart ssh.socket
else
sudo systemctl restart ssh
fi

daemon-reload reruns the generator, which builds a socket configuration that includes 443. On a server that has turned socket activation off and runs the old way, restarting the ssh service is enough.

If ufw is enabled, allow 443.

Terminal window
sudo ufw status | grep -q 'Status: active' && sudo ufw allow 443/tcp

Check that both 22 and 443 are in LISTEN state and that 443 returns an SSH banner. With socket activation, the process in the ss output is systemd, not sshd. That’s expected.

Terminal window
sudo ss -tlnp | grep -E ':(22|443) '
timeout 5 nc 127.0.0.1 443

Run these steps in an elevated PowerShell. Windows Server 2025 ships with OpenSSH Server installed. On Windows 11 and other versions, check whether it’s installed first.

Terminal window
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'

If State is NotPresent, install it and start the service. The config file is created the first time the service starts.

Terminal window
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType Automatic
Terminal window
Get-NetTCPConnection -LocalPort 443 -State Listen -ErrorAction SilentlyContinue

This should print nothing. If a web server such as IIS already uses 443, this approach won’t work.

On Windows, sshd reads %ProgramData%\ssh\sshd_config. The default file has #Port 22 commented out and ends with a Match Group administrators block for the administrators group. In sshd_config, settings after a Match line apply only to that block, up to the next Match line or the end of the file. So don’t append Port to the end of the file; put it at the top.

Terminal window
$f = "$env:ProgramData\ssh\sshd_config"
Copy-Item $f "$f.bak"
Set-Content -Path $f -Value (@('Port 22', 'Port 443') + (Get-Content $f)) -Encoding ascii
& "$env:WINDIR\System32\OpenSSH\sshd.exe" -t; if ($LASTEXITCODE -eq 0) { 'CONFIG_OK' }

If you already use an uncommented Port 22, add only Port 443.

Installing OpenSSH Server creates a firewall rule for port 22 (OpenSSH-Server-In-TCP). Port 443 needs its own rule.

Terminal window
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP-443' -DisplayName 'OpenSSH Server (sshd) 443' `
-Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 443

sshd reads its config file when the service starts, so restart it to apply the change.

Terminal window
Restart-Service sshd
Get-NetTCPConnection -LocalPort 22,443 -State Listen

Even with the server firewall open, packets won’t arrive if a rule in front of the server blocks them. For a cloud VM, add an inbound allow rule for 443 to its security group or network firewall. For a server at home or in an office, add it on the router. Limit the source to the public IP of the client that will connect. If the client moves between networks, you need the egress IP of each one.

If the “connection itself times out” row from section 1 also shows up on 443, the source IP in this step usually doesn’t match.

Connect with the port specified and check that the banner arrives.

Terminal window
ssh -v -p 443 vmuser@my-vm.example.com

If the -v output contains a line such as Remote protocol version 2.0, remote software version OpenSSH_9.6p1 Ubuntu-3ubuntu13.20, the SSH handshake over 443 worked. get_agent_identities: ssh_get_authentication_socket: Connection refused in the same output is a debug message saying the client couldn’t reach its ssh-agent socket. It has nothing to do with the server or the port, and ssh carries on authenticating with key files.

Writing two Port lines for one Host in ~/.ssh/config doesn’t make ssh fall back to 443 when 22 fails. For each setting, ssh uses the first value it obtains and ignores the rest. To use both ports, split them into two aliases.

~/.ssh/config
Host my-vm
HostName my-vm.example.com
User vmuser
Port 22
Host my-vm-443
HostName my-vm.example.com
User vmuser
Port 443

To pick the port automatically, use Match exec. The block applies when the command exits with status 0. Because the first obtained value wins, put the Match block above the Host block. The following example, for macOS, uses 443 only when the route to the destination goes through a utun tunnel interface.

~/.ssh/config
Match originalhost my-vm exec "route -n get %h 2>/dev/null | grep -q 'interface: utun'"
Port 443
Host my-vm
HostName my-vm.example.com
User vmuser
Port 22

%h is replaced with the host name being connected to. You can check which port applies without connecting.

Terminal window
ssh -G my-vm | grep -E '^(hostname|port) '
  • If a web server uses 443, this approach won’t work. This article doesn’t cover sharing one port between HTTPS and SSH (sslh and similar).
  • On networks that inspect content rather than port numbers and block the SSH protocol itself, 443 is blocked too. In that case the “connects, but no banner” row from section 1 shows up on 443 exactly as on 22.
  • If blocking port 22 is an organization’s policy, getting around it on 443 can break that policy. Ask the administrator for an exception, or look at official paths such as a cloud console’s connection feature or a bastion first.
  • The Ubuntu steps were confirmed up to a working SSH handshake on 443 against an Ubuntu 24.04 server. The Windows steps follow Microsoft’s documentation and the Win32-OpenSSH default config file, and weren’t run on an actual VM.

In this article, OpenSSH accepts SSH connections directly on port 443. What Changes When stunnel Wraps SSH in TLS? compares that setup with TLS termination in stunnel and explains how authentication differs.