SSH, or Secure Shell, is a cryptographic network protocol that lets you log in to a remote computer and run commands over an encrypted connection. It runs on TCP port 22 by default, uses public-key cryptography to verify the server and authenticate the user, and replaces insecure protocols such as Telnet that send passwords in plain text.
Key takeaways
- SSH encrypts everything — commands, output, and credentials — so a network observer cannot read or steal them.
- Key-based authentication is safer than passwords: the private key never leaves your computer.
- Port 22 is the default, but changing the port is not security — disable password logins and use keys instead.
Almost every Linux server in the world is managed the same way: an administrator opens a terminal, types a short command, and gets a shell on a machine that may be thousands of miles away. That command is SSH — and the reason it is trusted is that everything it carries is encrypted.
What is SSH?
SSH, or Secure Shell, is a cryptographic network protocol for operating network services securely over an unsecured network. Its most common use is remote login: you log in to a remote computer and run commands on it as if you were sitting in front of it.
SSH was designed in 1995 by Finnish researcher Tatu Ylonen, after a password-sniffing attack on his university network. It replaced Telnet and the older remote shell tools, which sent passwords and commands in plain text.
The protocol was later standardized by the IETF as SSH-2 in RFC 4251 through RFC 4254, published in 2006. The original SSH-1 is now obsolete and disabled by default in current OpenSSH releases, as the history of Secure Shell records.
The name covers two things. SSH is the protocol, described in those RFCs. OpenSSH is the program that implements it, released in 1999 by the OpenBSD developers, and it is what almost every Linux server and laptop actually runs.
How does SSH work?
SSH works in three layers, defined by RFC 4251: the transport layer sets up encryption and verifies the server, the user authentication layer proves who you are, and the connection layer multiplexes the encrypted tunnel into channels for shells, file transfers, and forwarding.
First, your client opens a TCP connection to the server, usually on port 22, and the two sides agree on protocol versions and algorithms. Then they perform a key exchange — typically Diffie-Hellman or elliptic-curve Diffie-Hellman — to derive a shared session key that encrypts everything after it.
Before any user credentials are exchanged, the client verifies the server. Every server has a permanent identity called a host key, and the client checks it against the key it saw last time. If the key has changed, SSH warns you — and that warning is worth taking seriously, because it can mean someone is intercepting the connection.
Only then does authentication happen, inside the encrypted channel. The connection layer then splits the tunnel into channels: one for your shell, others for file transfers or forwarded ports, all sharing the same encryption.
What is port 22, and why does SSH use it?
Port 22 is the default port for SSH, assigned by IANA in 1995. Ylonen asked for a free number sitting next to the protocols SSH was written to replace: 21 was FTP, 23 was Telnet, and 22 was unused.
The number carries no technical meaning. SSH would work identically on any port, and many servers run it elsewhere. Because 22 is the default, clients assume it unless told otherwise — with ssh -p 2222 user@server, or a port setting in ~/.ssh/config.
Moving SSH to another port does reduce the noise in your logs, because automated scanners sweep the whole internet on port 22 looking for weak passwords. But it is not security: a real attacker will find the port with a scan.
The defenses that matter are keys, not obscurity, as the port 22 guide also notes. If you manage servers, our guide to how to secure your Wi-Fi covers the same principle on your home network.
SSH vs Telnet: what is the difference?
SSH and Telnet do the same job — a remote shell — but Telnet does it in plain text and SSH does it encrypted. That one difference decides which one you should ever use.
| SSH | Telnet | |
|---|---|---|
| Encryption | Everything encrypted | Nothing encrypted |
| Passwords | Encrypted, or replaced by keys | Sent in plain text |
| Server identity | Verified by host key | Not verified |
| Default port | 22 | 23 |
| File transfer | SFTP and SCP built in | None — use FTP separately |
| Use today | Standard for remote access | Only on isolated, trusted networks |
Telnet still appears on old network equipment and in lab environments, but it should not be used for remote access over any network you do not fully control. Anyone on the path — a compromised router, a public Wi-Fi network — can read a Telnet session, including the password.
How does SSH authentication work?
SSH supports several ways to prove who you are, and they are not equal. Password authentication is the simplest and the weakest; key-based authentication is the standard for servers, and certificates are the standard for larger teams.
| Method | How it works | Security |
|---|---|---|
| Password | You type a password, sent inside the encrypted channel | Weak — guessable, phishable, brute-forced |
| Public key | Your private key proves your identity; the key never crosses the network | Strong — the standard for servers |
| Key plus second factor | A key and a one-time code, stacked with AuthenticationMethods | Stronger — two independent factors |
| Certificate | A signed certificate vouches for the key, with an expiry date | Strongest at scale — no authorized_keys to manage |
With key authentication, you generate a pair: a public key that goes on the server, usually in ~/.ssh/authorized_keys, and a private key that stays on your computer. When you connect, the server challenges your client to prove it holds the private key, without the key itself ever crossing the network. Protect the private key with a passphrase, and never share it or copy it to a server.
How do I set up SSH keys?
Setting up keys takes about two minutes, and it is the single biggest improvement you can make to a server's security. Do it before you disable password logins — otherwise you can lock yourself out.
- Generate a key pair. On your own computer, run
ssh-keygen -t ed25519 -C "[email protected]"and accept the default location. Set a passphrase when asked. - Copy the public key to the server. Run
ssh-copy-id user@server, then log in once with your password to confirm the key works. - Test key login. Run
ssh user@serveragain. It should ask for your key passphrase, not your account password. - Disable password logins. On the server, edit
/etc/ssh/sshd_config, setPasswordAuthentication no, and restart the SSH service. - Keep a backup. Store the private key in a password manager or an encrypted backup. If you lose it, you lose access.
On the server, the daemon is sshd and its configuration is /etc/ssh/sshd_config. On your computer, the client reads ~/.ssh/config first, then the system-wide client file. Confusing the two files is the most common reason an edit seems to have no effect.
What is SSH used for?
Remote login is only the start. Because SSH provides an encrypted, authenticated channel, a lot of infrastructure rides on top of it.
- File transfer: SFTP and SCP are SSH subsystems, so a file copy gets the same encryption and authentication as a login.
- Git: pushing code to GitHub, GitLab, or a self-hosted server usually happens over SSH, authenticated by your key.
- Automation: tools such as Ansible administer whole fleets of servers through SSH, running the same commands on hundreds of machines.
- Tunnels: SSH port forwarding carries a database connection or an internal web app through the encrypted channel, so it never travels in the clear.
How do I secure SSH properly?
Most SSH compromises are not protocol failures — they are configuration failures. Automated scanners try common passwords against port 22 all day, every day, and a weak password is the easiest way in.
- Use keys, disable passwords. Set
PasswordAuthentication noinsshd_configonce keys work. - Disable root login. Set
PermitRootLogin noso attackers cannot target the most powerful account directly. - Keep OpenSSH updated. Update the server regularly; old versions carry known flaws.
- Limit who can connect. Use
AllowUsersto name the accounts that may log in, and firewall port 22 to trusted addresses where possible. - Do not ignore host key warnings. Verify a changed fingerprint with the server owner before accepting it.
- Protect private keys. Use a passphrase, keep keys off shared machines, and remove old keys from
authorized_keyswhen people leave.
If a login fails, run the client with ssh -v user@server. The debug output shows each stage — connection, key exchange, host key check, authentication — and the last lines tell you exactly which stage broke.
Why is my SSH connection failing?
Three errors cover most failures. Match the message to the cause before changing settings at random.
- Connection refused: nothing is listening on that port — SSH may not be running, or you have the wrong host or port.
- Connection timed out: a firewall is blocking the connection, or the server is unreachable. Check the firewall and the address.
- Permission denied (publickey): the server rejected your key — check that the public key is in
authorized_keys, that file permissions are correct, and that you are using the right username.
Permissions matter more than most people expect: your home directory, ~/.ssh, and authorized_keys must not be writable by others, or OpenSSH will refuse the key.
You can check a server is reachable before troubleshooting SSH with our what is my IP tool.
For its public web services, use our SSL checker as well.
The bottom line
SSH is the encrypted replacement for Telnet: a remote shell, file transfer, and automation channel that verifies the server and keeps your credentials off the network.
Use it with keys, not passwords, disable root and password logins once keys work, and treat a host key warning as a stop sign until you have verified it. That is the whole recipe — and it is what keeps millions of servers safe.
Frequently asked questions
What is SSH in simple terms?
SSH is a secure way to control a computer somewhere else from your own computer. You type commands, they run on the remote machine, and everything travels inside an encrypted connection so nobody on the network can read it.
How does SSH work?
Your SSH client connects to the server on port 22, the two sides agree on encryption, and the client checks the server's host key to confirm it is the right machine. Then you prove who you are with a password or, better, a key pair, and an encrypted channel carries your shell session.
What port does SSH use?
SSH uses TCP port 22 by default, assigned by IANA in 1995. It sits between FTP on port 21 and Telnet on port 23, the protocols it was designed to replace. You can run SSH on another port, but that alone does not make it secure.
Is SSH secure?
Yes, when configured properly. SSH encrypts the connection and verifies the server's identity. It becomes insecure when password logins are left on with weak passwords, when host key warnings are ignored, or when private keys are shared or left unprotected.
What is the difference between SSH and Telnet?
Telnet sends everything, including passwords, in plain text, so anyone on the network can read it. SSH encrypts everything and verifies the server's identity. Telnet should not be used for remote access on any network you do not fully control.
What is an SSH key?
An SSH key is a pair of cryptographic keys: a public key you place on the server, and a private key you keep on your own computer. When you connect, the server challenges your client to prove it holds the private key, without the key itself ever crossing the network.
What is SSH used for besides remote login?
SSH also moves files with SFTP and SCP, runs automation tools such as Ansible, carries Git pushes, and tunnels other traffic through port forwarding. Many servers are managed entirely through SSH, with no screen or keyboard attached.
What does the SSH host key warning mean?
It means the server's host key has changed since you last connected, or you have never connected to this server before. A changed key can mean the server was rebuilt, or it can mean someone is intercepting your connection. Do not accept it blindly — verify the fingerprint with the server owner first.
Sources
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.
Checked against RFC 4251 through RFC 4254, which define the SSH protocol, and OpenSSH documentation.
How we write and fact-check →