Port reference › Remote access
Port 22 · SSH
Linux remote shell, SFTP, Git
TCP Remote access Exposure risk: Medium
What is port 22 used for?
Encrypted remote shell protocol. Used for server administration, file transfer (SFTP, SCP) and Git over SSH (git@github.com).
Well-known port (0-1023): opening it on Linux needs root (or CAP_NET_BIND_SERVICE).
Security notes
An SSH port open to the internet gets thousands of brute-force attempts a day. Disable password login (PasswordAuthentication no) and allow keys only. Restricting source IPs or running fail2ban helps further.
Allow port 22 through the firewall
This port is risky to expose, so the commands below allow only the IPs you specify.
# Replace 203.0.113.10/32 with the IP or network you want to allow
sudo ufw allow from 203.0.113.10/32 to any port 22 proto tcp
sudo ufw status # Replace 203.0.113.10/32 with the IP or network you want to allow
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.10/32" port port="22" protocol="tcp" accept'
sudo firewall-cmd --reload # Replace 203.0.113.10/32 with the IP or network you want to allow
sudo iptables -A INPUT -p tcp -s 203.0.113.10/32 --dport 22 -j ACCEPT # Replace 203.0.113.10/32 with the IP or network you want to allow
New-NetFirewallRule -DisplayName "Allow TCP 22" -Direction Inbound -Protocol TCP -LocalPort 22 -RemoteAddress 203.0.113.10/32 -Action Allow # Replace sg-0123456789abcdef0 with your security group ID
aws ec2 authorize-security-group-ingress --group-id sg-0123456789abcdef0 --protocol tcp --port 22 --cidr 203.0.113.10/32 Check whether port 22 is open
sudo ss -tlpn | grep ':22 ' netstat -ano | findstr :22 nc -zv SERVER 22
# Windows
Test-NetConnection SERVER -Port 22 sudo lsof -i :22 Ports used together
- 2222 SSH (alternate port) · Common alternative SSH port