Sub topic 1
How SSH Logins Work and Why Passwords Are a Weak Point
Prerequisites
You should be comfortable using a Linux or macOS command line, running ssh with a password, reading basic Unix file permissions, and editing a file with nano or vim. You also need an account on a remote Linux server.
The SSH client-server model
SSH, or Secure Shell, is a protocol for securely operating a remote computer. The client runs on your laptop. The server runs an SSH service, usually called sshd, on the remote computer.
When you run this command, your SSH client contacts the server:
ssh [email protected]The client and server first create an encrypted connection. They then authenticate two things:
- The client verifies that it is connected to the intended server.
- The server verifies that you are allowed to use the requested account.
These checks solve different problems. A server host key identifies the server. Your password or public key identifies you.
What happens during a password login
During the initial connection, SSH negotiates encryption and verifies the server's host key. Only after the encrypted session exists does the client send a password-authentication request.
The password is protected by the SSH encryption while it crosses the network. It is not normally transmitted as readable text. However, password authentication still has important weaknesses:
- People reuse passwords across services.
- Short or predictable passwords can be guessed.
- Attackers can capture passwords with phishing or malicious software.
- Internet-facing servers receive automated login attempts.
- A stolen password can often be used from any computer.
SSH can slow repeated attempts, but it cannot make a weak or reused password strong.
The first time you connect to a server, SSH may display a host-key fingerprint and ask whether you trust it. Compare this fingerprint with a value supplied through a trusted channel, such as your organization's console or documentation. Accepting an unexpected key can expose you to a man-in-the-middle attack, where another system impersonates the server.
Public key authentication
Public key authentication replaces a reusable secret with a key pair:
- A private key stays on your client. It proves your identity and must not be shared.
- A public key is installed on the server. It can be shared.
- The server stores accepted public keys in the account's
~/.ssh/authorized_keysfile.
The client proves that it controls the private key without sending the private key to the server. The server checks that proof against the stored public key.
This method resists password guessing because the server does not receive a password that can be reused elsewhere. It also supports separate keys for separate systems and makes access easier to revoke. The private key still needs protection. Usually, you protect it with a passphrase.
“Passwordless” means that SSH does not ask for the account password during login. It does not necessarily mean that no passphrase is required. An SSH agent can remember the unlocked key for a session.
| Credential | Stored where | Main risk | Typical protection |
|---|---|---|---|
| Account password | Password database on the server | Guessing, reuse, phishing | Strong unique password and limits |
| Private key | Client computer | Theft of the key file | Passphrase and file permissions |
| Public key | Server account | Unauthorized modification | Protected `~/.ssh` and `authorized_keys` |
Inspecting the connection
Verbose mode helps you see which stage fails without exposing your private key:
ssh -v [email protected]Look for messages about the host key, offered authentication methods, and accepted or rejected keys. Do not paste logs containing usernames, hostnames, or other sensitive details into public forums without reviewing them.
Exercise
Exercise
Why does SSH verify the server host key separately from your user credentials?
Show answer
The host key proves which server you reached, while your credentials prove whether you may use an account on that server. A trusted server identity prevents an attacker from impersonating the destination.