Port 22 — SSH / SFTP
TCP well-known
What runs on port 22
Secure Shell — remote terminal access, and the transport for SFTP and SCP. Also what Git uses over SSH.
SSH multiplexes far more than a shell: SFTP, SCP, port forwarding, and Git all ride the same connection. That makes 22 the most valuable port on most machines and, correspondingly, the most attacked — an internet-facing host sees automated password attempts within minutes. The effective defences are key-only authentication and rate limiting; moving to a high port cuts log noise but stops nothing that scans the full range. If a connection hangs after the banner rather than failing outright, the usual cause is a MTU or keepalive problem rather than authentication.
Security considerations
The single most brute-forced port on the internet. Disable password authentication, use keys only, and consider fail2ban. Moving to a non-standard port reduces log noise but is not security.
Checking whether something is listening
# Linux / macOS — what is bound to the port
sudo lsof -i :22
sudo ss -lntp | grep :22
# Windows
netstat -ano | findstr :22
Get-NetTCPConnection -LocalPort 22
# is it reachable from outside?
nc -zv example.com 22
curl -v telnet://example.com:22
Freeing the port
# find the process, then stop it
sudo lsof -ti :22 | xargs kill # Linux / macOS
netstat -ano | findstr :22 # note the PID, then:
taskkill /PID <pid> /F # Windows
Should this port be open to the internet?
Only with care. SSH is designed to be exposed, but it is also the most brute-forced port on the internet. Keys only, no password authentication, and rate limiting.
Opening or blocking port 22
Finding the port is usually the first half of the job. Start narrow — the second rule is there for services that genuinely serve the public, and most do not:
# ufw — Debian, Ubuntu
sudo ufw allow from 10.0.0.0/8 to any port 22 proto tcp
sudo ufw allow 22/tcp # only if it genuinely serves the public
# firewalld — RHEL, Fedora, CentOS
sudo firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=10.0.0.0/8 port port=22 protocol=tcp accept'
sudo firewall-cmd --reload
# iptables, if you are still there
sudo iptables -A INPUT -p tcp --dport 22 -s 10.0.0.0/8 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -j DROP
# Windows
New-NetFirewallRule -DisplayName "SSH / SFTP 22" -Direction Inbound -Protocol TCP -LocalPort 22 -RemoteAddress 10.0.0.0/8 -Action Allow
10.0.0.0/8 stands in for a private range — substitute your own. Note that a firewall rule does not undo a service bound to 0.0.0.0; it only stops packets reaching it, and a misconfigured or disabled firewall then exposes it immediately.
Quick reference
| Port | 22 |
| Protocol | TCP |
| Service | SSH / SFTP |
| Range | Well-known (0–1023) — binding requires root on Unix |
Frequently asked questions
What is port 22 used for?
Secure Shell — remote terminal access, and the transport for SFTP and SCP. Also what Git uses over SSH.
Is it safe to open port 22?
The single most brute-forced port on the internet. Disable password authentication, use keys only, and consider fail2ban. Moving to a non-standard port reduces log noise but is not security.
How do I check if port 22 is open?
Locally, sudo lsof -i :22 on macOS or Linux, or netstat -ano | findstr :22 on Windows. From outside, nc -zv host 22 tells you whether anything answers.
Why do I get "address already in use" on port 22?
Another process is bound to it — often a previous run of your own program that did not exit cleanly. Find it with lsof -ti :22 and stop it, or configure your application to use a different port.
Can I change the port this service uses?
Almost always yes, in the service's configuration. Moving off a default port reduces automated scan noise, but it is obfuscation rather than security — a real attacker scans all 65,535.