PortScan › Port guide › Port 22
Port 22 (SSH): Is It Safe to Leave Open? Secure Configuration
Port 22 is SSH remote access. Essential for server admin, but password logins make it a brute-force target. Practical hardening: key auth, no root login, IP limits.
What is port 22?
SSH (Secure Shell) is the standard way to open an encrypted terminal session on a remote server. Linux servers, cloud VMs and the admin interfaces of many routers and NAS devices all run SSH on port 22. The connection itself is strongly encrypted, so unlike FTP or Telnet, simply "being open" is not dangerous in itself.
The problem is authentication. An internet-facing port 22 receives thousands of automated login attempts a day. If password login is enabled and the password is weak, it is only a matter of time.
When it is normally open
- Remote administration of cloud servers and VPSes — the most common and perfectly legitimate case
- Git hosting servers (GitHub accepts git over port 22)
- Transferring files with SFTP
Risks if it is open
Constant brute forcing
Open port 22 on a fresh VPS and within minutes Failed password for root starts piling up in /var/log/auth.log. Attack bots cycle through common usernames such as root, admin, ubuntu and pi, combined with leaked password lists.
Vulnerabilities in OpenSSH itself
Rare, but they happen. regreSSHion (CVE-2024-6387), disclosed in 2024, allowed pre-authentication remote code execution in OpenSSH 8.5p1 through 9.7p1 on glibc-based Linux. SSH is a service where security updates should never wait.
Leaked private keys
Even with key authentication, a private key file leaked from a laptop or CI server lets an attacker walk straight in. Protect private keys with a passphrase.
Security checklist
- Allow key authentication only: in
/etc/ssh/sshd_configsetPasswordAuthentication noandKbdInteractiveAuthentication no. Before applying, confirm in a separate window that you can log in with your key. - Block direct root login:
PermitRootLogin no(orprohibit-passwordto allow keys only). - If you only connect from known locations, allow just those IPs in the firewall:
sudo ufw allow from 203.0.113.10 to any port 22 proto tcp. - Use fail2ban or CrowdSec to block IPs that fail repeatedly.
- Moving SSH from 22 to something like 2222 reduces log noise but adds no real security. A single port scan will find it.
- Going further, the most reliable approach is to close SSH to the internet entirely and expose it only inside a VPN such as Tailscale or WireGuard.
How to check whether port 22 is open
From outside (is it exposed to the internet?)
Whether your server or home router accepts port 22 from the internet can only be confirmed by connecting from outside. A check from inside the same network bypasses the router's firewall and gives a different answer.
PortScan opens a real TCP connection from the Cloudflare edge and reports Open, Closed or Filtered. Members can scan every port on their own IP for free and other targets free once a day.
Check port 22On the server (what is listening?)
Windows (PowerShell):
netstat -ano | findstr ":22 "
Get-NetTCPConnection -LocalPort 22 -State Listen | Select LocalAddress,OwningProcess
Linux:
sudo ss -tlnp | grep ':22 '
If it listens on 0.0.0.0 or [::] it is open on every network; 127.0.0.1 means only that machine can connect. To test port 22 on a server from another computer, use Test-NetConnection server-address -Port 22 on Windows or nc -vz server-address 22 on Linux and macOS.
How to close or restrict port 22
The best fix is to turn the service off or make it listen only on 127.0.0.1 (see the checklist above). If you need the service but must keep it off the internet, use a firewall.
Windows Firewall
# Administrator PowerShell
New-NetFirewallRule -DisplayName "Block TCP 22" -Direction Inbound -Protocol TCP -LocalPort 22 -Action Block
# To allow a single IP instead (block rules take precedence, so use this instead of the rule above)
New-NetFirewallRule -DisplayName "Allow TCP 22 from office" -Direction Inbound -Protocol TCP -LocalPort 22 -RemoteAddress 203.0.113.10 -Action Allow
Linux (ufw)
sudo ufw deny 22/tcp
# Allow a single IP only
sudo ufw allow from 203.0.113.10 to any port 22 proto tcp
On a cloud server, also check port 22 in the security group (inbound rules), which is separate from the OS firewall. For services running in Docker, the rules Docker creates can bypass ufw, so binding the port to localhost with -p 127.0.0.1:22:22 is the reliable option.
Router
At home or in a small office, open the router's admin page and check whether port 22 is in the port forwarding list, whether DMZ is enabled, and whether any program opened ports by itself through UPnP. If any of the three applies, port 22 on your PC is directly visible from the internet.
How to read the scan result
- Open — something accepted a connection on port 22. Work through the risks above.
- Closed — the packet reached the device, but nothing is listening on that port, so it was refused immediately (RST). The service is off.
- Filtered — no response. A firewall or the ISP is dropping packets, or the device is off. From an exposure point of view this is the safest state.
The verdict can depend on where you connect from. Many ISPs (including most Korean ISPs) block some ports such as 135, 139 and 445 on their network, so the same server can look Filtered from inside that network and Closed from abroad.
FAQ
- Port 22 is open. Is that dangerous?
- If only key authentication is allowed and OpenSSH is up to date, you are generally fine. If password login is enabled, change that right away.
- The scan banner shows a string like SSH-2.0-OpenSSH_8.9p1
- That is the version string the server sends right after you connect. Attackers see it too, so check whether that version has known vulnerabilities and update.
Related ports
Last updated 2026-11-04 · Use this guide to check systems you manage. Scanning systems without permission may carry legal liability.