Port / TCP
22SSH / SFTP
SSH provides an authenticated, encrypted channel for interactive shells, port forwarding, and SFTP/SCP transfers.
If it is internet-facing: Port 22 is legitimate in the right place, but exposed carelessly it widens the attack surface noticeably.
Exposure
Internet-facing
Transport
Encrypted by default
Risk if public
Elevated
Exposure verdict
Port 22 is meant to answer from the internet, and it protects the session itself. What remains is authentication strength, patch level, and rate limiting.
The session is protected from the first byte, so there is no plaintext phase for an on-path attacker to strip or read.
Assigned by IANA through a review process. On Unix systems a process needs root or the CAP_NET_BIND_SERVICE capability to bind here, which is why containers so often remap these to a higher port.
Grouped with the other remote access ports so a rule written for one can be checked against its neighbours.
What actually goes wrong
2 notes- A public SSH port will be probed continuously; key-only authentication removes the value of that noise.
- Agent forwarding into an untrusted host hands that host the use of your keys for the life of the session.
Recommended firewall rule
Allow it, and harden the service
This port is expected to answer from anywhere, so the firewall is not where its security comes from.
ufw
sudo ufw allow 22/tcpiptables
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPTCheck what is really there
Listening locally
sudo ss -tlpn 'sport = :22'The bind address is the answer that matters: 127.0.0.1 is local-only, 0.0.0.0 and :: mean every interface.
Listening (macOS)
sudo lsof -nP -iTCP:22 -sTCP:LISTENmacOS ships lsof rather than ss; this names the owning process and user.
From outside
nmap -sV -Pn -p 22 <host>A version probe confirms whether SSH / SFTP is actually what answers, rather than trusting the number. Only scan hosts you are authorised to test.
Reachability
nc -vz <host> 22The quick yes/no when you only need to know whether a path exists through the firewall.