Port 22 (SSH): What It Is & Security Guide

May 16, 2026
Updated May 16, 2026 Port Security Guides port 22 ssh port 22 security what is port 22 open port 22 ssh security secure shell ssh hardening port 22 risks ssh attacks how to secure ssh ssh vulnerabilities tcp port 22 ssh best practices ssh remote access fail2ban iptables ufw

What is Port 22 (SSH)? Understanding Secure Shell

In the vast landscape of network communication, certain ports stand out due to their critical role in system administration and data transfer. Among these, Port 22 is arguably one of the most recognized and essential. It is the default port for the Secure Shell (SSH) protocol, a cryptographic network protocol that enables secure remote access to computers and servers over an unsecured network.

SSH provides a secure channel over an unsecure network by using strong cryptography to encrypt all communications between the client and the server. This includes authentication, commands, and data transfers, making it an indispensable tool for system administrators, developers, and anyone needing to manage remote systems securely. Without SSH, managing remote servers would be a significantly more perilous task, exposing sensitive information and control to potential eavesdropping and tampering.

However, its ubiquity and critical function also make Port 22 a prime target for malicious actors. An improperly secured or unnecessarily exposed Port 22 can become a significant vulnerability, leading to unauthorized access, data breaches, and complete system compromise. This guide will delve into the technical details of Port 22, explore its security risks, outline common attack vectors, and provide comprehensive strategies for hardening your SSH configurations to ensure robust security.

Want to check your site right now?

Port Scanner →  ·  Website Vulnerability Scanner

Port 22 Technical Details: The Foundation of SSH

Understanding the technical underpinnings of Port 22 and the SSH protocol is crucial for appreciating its security implications.

DetailValue
Port Number22
ProtocolTCP
ServiceSSH (Secure Shell)
Risk LevelMedium (High if unsecured)
DescriptionSecure remote access, command execution, and file transfer.

Protocol: TCP (Transmission Control Protocol)

SSH primarily operates over TCP, a connection-oriented protocol that guarantees reliable, ordered, and error-checked delivery of a stream of bytes between applications running on hosts communicating over an IP network. This reliability is vital for SSH, as it ensures that commands sent to a remote server are received in the correct order and without corruption, and that file transfers are complete and accurate.

How SSH Works: A Secure Handshake

When an SSH client attempts to connect to an SSH server (daemon, typically `sshd`), a multi-step process unfolds:

  1. Connection Establishment: The client initiates a TCP connection to Port 22 on the server.
  2. Protocol Version Exchange: Both client and server exchange their supported SSH protocol versions.
  3. Algorithm Negotiation: They agree on a set of cryptographic algorithms for encryption, hashing, and key exchange.
  4. Key Exchange: A Diffie-Hellman key exchange algorithm is used to establish a shared secret key, which will be used for symmetric encryption of the session. This step also involves the server sending its public host key to the client. The client verifies this key against its known_hosts file to prevent Man-in-the-Middle (MITM) attacks.
  5. Authentication: The client authenticates itself to the server. Common methods include:
    • Password Authentication: The client sends a username and password, which the server verifies.
    • Public Key Authentication: The client sends its public key, and the server checks if it matches an authorized key for the user. If it does, the server challenges the client to prove ownership of the corresponding private key. This is generally considered the most secure method.
  6. Session Establishment: Once authenticated, a secure, encrypted channel is established, allowing the client to execute commands, transfer files (via SCP or SFTP), or tunnel other network services.

The use of strong encryption and robust authentication mechanisms makes SSH a cornerstone of secure remote administration. However, the strength of SSH security heavily relies on proper configuration and ongoing vigilance.

Security Risks of Open Port 22

While SSH is designed for security, an open Port 22, especially without proper hardening, presents a significant attack surface. Attackers constantly scan the internet for open ports, and Port 22 is a prime target due to its administrative privileges. The risks associated with an exposed and inadequately secured SSH port can range from minor disruptions to catastrophic data breaches.

Common Attacks on Port 22

Attackers employ various sophisticated techniques to target Port 22. Understanding these methods is the first step in building effective defenses.

How to Check if Port 22 is Open

Before you can secure Port 22, you need to know if it's open and accessible from the internet or within your local network. There are several methods to check the status of Port 22 on your systems.

Using Nmap (Network Mapper)

Nmap is a powerful, open-source tool for network discovery and security auditing. It can quickly scan a target host or network for open ports.

To check if Port 22 is open on a specific target from your local machine:

nmap -p 22 target.com

Replace target.com with the IP address or hostname of the server you want to check. If Port 22 is open, Nmap will report it as 'open'.

To check for all common ports, including 22:

nmap target.com

To perform a more aggressive scan (use with caution and only on systems you own or have permission to scan):

nmap -sV -sC -p 22 target.com
  • -sV: Attempts to determine service/version info.
  • -sC: Enables default script scanning.

Using Local System Commands

To check if your own server is listening on Port 22:

On Linux/Unix systems:

sudo netstat -tulnp | grep 22

Or, using the more modern `ss` command:

sudo ss -tulnp | grep 22

These commands will show if a process (specifically `sshd`) is listening on TCP port 22.

Using Online Port Scanners

Online port scanners provide an external perspective, showing how your ports appear to the internet. This is crucial for understanding your true exposure.

You can easily scan your public IP address for open ports, including Port 22, using a reliable online tool. For a quick and free check, consider using the Secably Port Scanner. Simply enter your public IP address or domain name, and the tool will report which ports are open and accessible from the internet.

Regularly checking your open ports is a fundamental security practice to ensure that only necessary services are exposed and that your firewall rules are functioning as intended.

Free Security Tools

Scan your website, check open ports, find subdomains — no signup required.

See all tools →

How to Secure Port 22: Essential SSH Hardening Techniques

Securing Port 22 is paramount for protecting your servers and data. Implementing a layered defense strategy significantly reduces the risk of compromise. Here are comprehensive steps to harden your SSH configuration:

When Should Port 22 Be Open? Legitimate Use Cases

Despite the security risks, Port 22 is a fundamental component of modern server management and has many legitimate and essential uses. It should be open when you need to perform any of the following tasks:

  • Remote Server Administration: This is the primary use case. System administrators use SSH to securely log into remote servers, execute commands, configure software, and manage system resources from anywhere in the world.
  • Secure File Transfers (SFTP/SCP): SSH provides secure protocols for transferring files. SCP (Secure Copy Protocol) and SFTP (SSH File Transfer Protocol) allow users to copy files between hosts over an encrypted SSH connection, protecting data in transit.
  • SSH Tunneling and Port Forwarding: SSH can create secure tunnels to forward arbitrary TCP ports. This is useful for accessing services that are not directly exposed to the internet (e.g., a database server on a private network) or for encrypting traffic for other applications.
  • Version Control Systems (Git over SSH): Many developers use SSH to authenticate and communicate with Git repositories (e.g., GitHub, GitLab, Bitbucket). This provides a secure and efficient way to push and pull code.
  • Automated Deployments and Script Execution: DevOps pipelines and automation scripts frequently use SSH to deploy applications, run remote commands, and manage configurations on target servers without human intervention.
  • Backup and Synchronization: Tools like rsync can leverage SSH to securely synchronize files and directories between servers, ensuring data integrity and confidentiality during backup operations.

In all these scenarios, the benefits of secure remote access outweigh the risks, provided that robust security measures are in place to protect Port 22.

Is port 22 dangerous?

Port 22 itself is not inherently dangerous; it's the default port for SSH, a highly secure protocol. However, an open Port 22 becomes dangerous if it's not properly secured. Without strong authentication (like SSH keys), disabled root login, and firewall restrictions, it's a prime target for brute-force attacks and other exploits that can lead to unauthorized access and system compromise. When configured correctly, SSH on Port 22 is a safe and essential tool.

Should I close port 22?

You should close Port 22 if you do not need remote SSH access to your server. If you manage your server locally or through an alternative secure method (like a VPN), closing Port 22 eliminates a significant attack surface. However, if you require remote administration, file transfers, or other SSH-dependent services, you must keep it open but implement all the hardening measures discussed in this guide to protect it rigorously.

How do I block port 22?

You can block Port 22 using your system's firewall. Here are common commands:

Using UFW (Uncomplicated Firewall) on Ubuntu/Debian:

sudo ufw deny 22
sudo ufw enable

Using iptables on CentOS/RHEL/Fedora:

sudo iptables -A INPUT -p tcp --dport 22 -j DROP
sudo service iptables save (or sudo netfilter-persistent save on some systems)

Remember to ensure you have alternative access to your server before blocking SSH, or you might lock yourself out.

What runs on port 22 by default?

By default, the SSH daemon (sshd) runs on Port 22. This is the server-side component of the Secure Shell protocol, which listens for incoming SSH connections from clients. When a client attempts to connect, `sshd` handles the authentication, encryption, and session management, allowing secure remote command execution and file transfers.

Scan for these vulnerabilities

Secably automatically detects the issues discussed in this article.

Start Free Scan