Network security

SSH Port: What Port SSH Uses, How to Change It and Secure It

SSH listens on TCP port 22 by default, a number assigned by IANA in 1995. Here is what that means, when to change it, and the hardening steps that actually matter.

Cysoro Security TeamPublished · 7 min read
$ ssh user@server Connecting to port 22… ✓ key accepted ✓ encrypted session TCP 22 ssh -p 2222 NETWORK SECURITY SSHport 22 The default door to your servers.
Quick answer

The SSH port is TCP port 22 by default. IANA assigned port 22 to the Secure Shell protocol in 1995, and every SSH client and server assumes it unless told otherwise. You can change it in the server config or with ssh -p, but moving the port only hides SSH from casual scans — real security comes from key-based login, disabled password auth and fail2ban or firewall rules.

Key takeaways

  • SSH uses TCP port 22 by default, assigned by IANA in 1995 between FTP (21) and Telnet (23).
  • Changing the port reduces scanner noise but is not real security — disable password login and use SSH keys instead.
  • Check whether port 22 is open with ssh, nmap or telnet, and restrict who can reach it with a firewall.

Every time you type ssh user@server, your computer quietly connects to port 22. It is one of the best-known numbers in networking — and one of the most attacked. Here is what the SSH port is, why it is 22, and how to use it safely.

What is the SSH port?

The SSH port is the network port that the SSH daemon (sshd) listens on for incoming connections. By default that port is TCP port 22, and every SSH client assumes it unless you say otherwise.

SSH, or Secure Shell, is the protocol administrators use to log in to remote servers, transfer files with SFTP and SCP, and tunnel other traffic through an encrypted connection. When you run ssh user@host, you are really running ssh -p 22 user@host — the -p 22 is just implied.

The port number is only the front door. Once the connection is made, SSH negotiates encryption, authenticates you with a password or a key, and then gives you an encrypted session. The port itself does not make the connection secure; the protocol does.

Why is the SSH port 22?

Port 22 was assigned to SSH by IANA in July 1995, just before the first public release of SSH. The protocol's creator, Tatu Ylonen, asked for a free port in the 1–255 range, and 22 was available.

The choice was deliberate. SSH was built to replace Telnet (port 23) and FTP (port 21), the two insecure protocols of the time. Port 22 sat neatly between them, which made the assignment easy to remember. As SSH.com's account of the story tells it, IANA replied the next day: port 22 was assigned to ssh.

The number carries no technical meaning. SSH would work identically on port 2222, 443 or any other free port. The assignment is recorded in the IANA Service Name and Transport Protocol Port Number Registry, which lists ssh on port 22 for TCP, UDP and SCTP, with RFC 4251 as the reference.

What uses port 22?

Port 22 is used by far more than interactive logins. Because SSH is a general-purpose encrypted channel, a large share of infrastructure work rides on it.

  • Remote shell access — administrators logging in to Linux, macOS, BSD and Windows servers.
  • SFTP and SCP — secure file transfers, both built on top of SSH.
  • Git hosting — pushing and pulling code over SSH, for example git@github.com.
  • Automation — Ansible, Terraform and CI/CD runners administer fleets over SSH.
  • Tunnels and port forwarding — carrying database connections and internal web apps through an encrypted channel.
  • Remote file managers — tools like WinSCP and FileZilla connect over SFTP on port 22.

That ubiquity is why port 22 matters. If it is open and misconfigured, an attacker does not just get a login prompt — they get a path to your servers, your code and your data.

How an SSH connection on port 22 works Your computer SSH client ssh user@server Encrypted tunnel keys exchanged, traffic encrypted Server sshd listening on TCP port 22 The port is only the meeting point. Encryption and authentication happen after the connection opens. Change the port and the tunnel still works — the client just has to know the new number.
An SSH client connects to TCP port 22, then builds an encrypted session. Illustration by Cysoro.

Is SSH port 22 TCP or UDP?

SSH uses TCP in practice. TCP gives SSH the reliable, ordered delivery it needs for an interactive session, and every SSH client and server speaks TCP by default.

IANA also registers port 22 for UDP and SCTP, but that is mostly a formality of the registry — standard SSH implementations do not use UDP. When you open a firewall for SSH, open TCP 22 (or your custom port). Opening UDP 22 as well adds nothing and is not needed.

How do I check if SSH port 22 is open?

There are three quick ways to test whether a server is listening on port 22, from simplest to most detailed.

  1. Just connect: run ssh user@host. A password or key prompt means SSH is reachable. A timeout means the port is blocked or nothing is listening.
  2. Use nmap: run nmap -p 22 host. It reports the port as open, closed or filtered, and often shows the SSH version.
  3. Use telnet or nc: run telnet host 22 or nc -vz host 22. If SSH is there, you will see a banner like SSH-2.0-OpenSSH_9.6.

The banner itself is worth noting: it reveals the SSH software and version. Attackers use that to pick exploits, which is one reason some administrators hide or shorten the banner. On your own server, check the banner from outside with telnet to see what the internet sees.

How do I change the SSH port?

Changing the port takes two steps: tell the server to listen somewhere else, and tell your clients where to find it.

On the server

Edit /etc/ssh/sshd_config and change the Port line, for example Port 2222. Then restart the SSH service with sudo systemctl restart sshd and open the new port in your firewall before closing the old one.

Keep your current session open while you test the new port in a second terminal. If something goes wrong, you can still fix it from the session you already have. Locking yourself out of a remote server is the most common mistake here.

On the client

Connect with ssh -p 2222 user@host. To avoid typing the flag every time, add the host to ~/.ssh/config:

Host myserver
HostName 203.0.113.10
Port 2222
User deploy

After that, ssh myserver connects on the right port automatically. For scp, the flag is a capital -P — scp -P 2222 file user@host:/tmp/ — a small detail that trips people up regularly.

Should you change the SSH port from 22?

Changing the port is worth doing, but only with honest expectations. It is security through obscurity, and it has a real but limited benefit.

Staying on port 22Moving to a custom port
Automated scansConstant brute-force attempts fill your logsMost drive-by scans never find SSH
Determined attackerFinds SSH immediatelyFinds SSH with a quick port scan
Log noiseThousands of failed logins a dayNear silence
ConvenienceWorks everywhere with no flagsNeeds -p or an ssh config entry
Real securityDepends on authentication hardeningDepends on authentication hardening

A fresh server on port 22 will see failed login attempts within minutes of going online. Moving the port makes that noise disappear, which makes real alerts easier to spot. But a port scan takes seconds, so a custom port alone stops nobody who is actually targeting you.

How do I secure the SSH port?

These are the controls that actually stop SSH attacks. Apply them in this order.

SSH hardening, in order of impact 1. Use SSH keys, disable password loginPasswordAuthentication no — brute force becomes impossible 2. Disable root loginPermitRootLogin no — attackers must guess a username too 3. Restrict who can connectFirewall allowlist, AllowUsers, or a bastion host / VPN 4. Add fail2ban or rate limitingBan IPs after a few failed logins; slows every guessing attack 5. Move off port 22 (optional)Cuts log noise; do it last, after the real controls
Hardening SSH in order of impact — the port change comes last. Illustration by Cysoro.

1. Use SSH keys and disable password login

This is the single most important step. Generate a key pair with ssh-keygen -t ed25519, copy the public key to the server with ssh-copy-id, then set PasswordAuthentication no in sshd_config. Once passwords are off, brute-force attacks cannot succeed at all.

2. Disable root login

Set PermitRootLogin no. The root username is the same on every Linux server, so it is the first account attackers try. Forcing them to guess a username as well as a key makes the attack far harder.

3. Restrict who can reach the port

Use a firewall to allow SSH only from your office IP, your VPN, or a bastion host. If that is not possible, use AllowUsers in sshd_config to limit logins to named accounts. Fewer people who can reach the port means fewer chances for an attacker.

4. Add fail2ban or rate limiting

Fail2ban watches the SSH logs and blocks IPs after a handful of failed logins. It is a simple, effective second layer that turns a guessing attack into a slow crawl.

5. Keep SSH updated

OpenSSH vulnerabilities do appear, and old versions are a favorite target. Keep the server patched, and check the version your banner shows against current releases.

Common ports near 22: a quick reference

SSH sits in a neighborhood of classic service ports. Knowing them helps when reading firewall rules or scan results.

PortServiceNotes
20–21FTPFile transfer, unencrypted — SSH/SFTP replaced it
22SSH / SFTP / SCPEncrypted remote login and file transfer
23TelnetUnencrypted remote login — never expose it
25SMTPMail transfer between servers
53DNSDomain name resolution, TCP and UDP
80HTTPUnencrypted web traffic
443HTTPSEncrypted web traffic
3389RDPWindows Remote Desktop — a frequent attack target

Port 2222 is the most common alternate SSH port, followed by 22022 and 2022. None of them is a standard — they are just conventions people pick when they move off 22.

Common SSH port mistakes

A few errors show up again and again. Avoid them and you will save yourself an afternoon of troubleshooting.

  • Closing port 22 before testing the new one. Always test the new port in a second session first.
  • Forgetting the firewall. Changing sshd_config without opening the new port in the firewall leaves you locked out.
  • Using -p with scp. Lowercase -p in scp preserves file times; the port flag is capital -P.
  • Thinking a custom port is enough. It is not. Password login left enabled on a moved port is still a brute-force target.
  • Leaving Telnet or FTP open. Moving SSH while Telnet still listens on port 23 defeats the purpose entirely. Our small business cybersecurity checklist covers closing unused services alongside backups and updates.

The bottom line

The SSH port is 22 because IANA assigned it there in 1995, between the two protocols SSH replaced. It is a sensible default, and there is nothing wrong with keeping it — as long as SSH itself is hardened.

Move the port if the log noise bothers you, but spend your real effort on keys, disabled password login and firewall allowlists — the controls our attack surface management overview starts with.

You can check what the internet can see of your own services with the free what-is-my-ip tool.

Frequently asked questions

What is the SSH port?

The SSH port is TCP port 22. It is the default port the SSH daemon (sshd) listens on and the port SSH clients connect to unless you specify a different one.

Why is SSH on port 22?

IANA assigned port 22 to SSH in July 1995, days before the first public release. Creator Tatu Ylonen picked it because it was free and sat between FTP on port 21 and Telnet on port 23, the two protocols SSH was designed to replace.

Is SSH port 22 TCP or UDP?

SSH primarily uses TCP. IANA also lists port 22 for UDP and SCTP, but in practice SSH connections run over TCP, and firewalls should open TCP 22 for SSH.

Should I change the SSH port from 22?

Changing it cuts down automated login attempts and log noise, which is useful, but it does not stop a determined attacker who can port-scan your server. Treat it as a minor extra, not a security control, and always harden authentication as well.

How do I connect to SSH on a different port?

Use ssh -p followed by the port number, for example ssh -p 2222 user@server. For scp use a capital -P, and for sftp use -P as well. You can also set a default port per host in ~/.ssh/config.

How do I check if SSH port 22 is open?

Try ssh user@host, or run nmap -p 22 host, or telnet host 22. If SSH is listening you will see an SSH banner such as SSH-2.0-OpenSSH. If the connection times out, the port is blocked or nothing is listening.

Is it safe to leave port 22 open to the internet?

It can be, if SSH is hardened: key-only login, password authentication disabled, root login disabled, and a firewall or fail2ban limiting connection attempts. An unhardened server on port 22 will be found and brute-forced within hours.

Sources

  1. IANA — Service Name and Transport Protocol Port Number Registry
  2. RFC 4251 — The Secure Shell (SSH) Protocol Architecture
  3. SSH.com — The story of the SSH port is 22
  4. Cisco Duo — What is SSH? Secure shell explained
  5. OpenBSD — sshd_config manual page
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against the IANA port registry, RFC 4251, SSH.com's history of the port assignment and the OpenSSH sshd_config manual.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free