Module 1 · 1.3
English
The first SSH login
Module 1: Your first server · Reading time: 10 minutes
Learning objective: After this lesson you can log in to your server with SSH for the first time, check the server's fingerprint before you trust it, and know what to do when you get the warning that the server's identity has changed.
Key concepts: SSH, client and server, port 22, version banner, host key, fingerprint (SHA256), known_hosts, trust on first use, "REMOTE HOST IDENTIFICATION HAS CHANGED", PowerShell and Terminal
What SSH is
SSH (Secure Shell) is the encrypted connection you use to manage a server remotely. You type on your own computer, and the commands run on the server. Everything that goes over the line, including your password, is encrypted.
There are two sides:
- the SSH client on your own computer: the program
ssh. On macOS and Linux it is included by default. On Windows 10 (from version 1809) and Windows 11, the OpenSSH client is part of Windows; you use it in PowerShell or Windows Terminal. If it is missing, add it via Settings, Optional features, "OpenSSH Client". Programs with windows such as PuTTY work too, but in this course we usessh. - the SSH server on the VPS: the program
sshd(from OpenSSH). By default it listens on port 22.
Logging in
You log in with a username and the server's address:
PS C:\Users\anna> ssh root@192.0.2.10Or with a name, if you have set one up in DNS (lesson 7.1):
anna@laptop:~$ ssh root@web1.example.comThe first time, you see something like this:
The authenticity of host '192.0.2.10 (192.0.2.10)' can't be established.
ED25519 key fingerprint is SHA256:Xq3aTnPpC0m1o4cJ2kVqY8mWb7rZs5dLfE6hUyN9tKs.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])?This is the most important moment of this lesson. Do not type yes blindly.
The host key and the fingerprint
Every SSH server has one or more host keys: key pairs the server uses to prove who it is. The public parts are stored on the server in /etc/ssh/, for example /etc/ssh/ssh_host_ed25519_key.pub. With every connection, the server shows that it has the secret part.
A fingerprint is a short summary (a hash) of such a public key. By default OpenSSH shows the SHA256 form: SHA256: followed by 43 characters.
The question "Are you sure you want to continue connecting?" means: your computer does not know this server yet. Who guarantees that you are talking to your VPS and not to someone intercepting the traffic? Nobody, unless you compare the fingerprint with a trusted source.
That source is your provider's console (lesson 1.2). There you are not talking to the server over the network. Log in to the console and look up the fingerprint:
root@web1:~# ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
256 SHA256:Xq3aTnPpC0m1o4cJ2kVqY8mWb7rZs5dLfE6hUyN9tKs root@web1 (ED25519)If it matches exactly what the client shows, type yes. You can also paste the fingerprint itself instead of yes; then ssh compares it for you. If it differs, stop and find out why (wrong IP address, server reinstalled, or something more serious).
Pay attention to the type: the client names the type (ED25519, ECDSA or RSA). Compare the fingerprint of the same type. Many images also print the fingerprints in the console on first boot (cloud-init), between lines such as BEGIN SSH HOST KEY FINGERPRINTS.
known_hosts and trust on first use
When you type yes, you see:
Warning: Permanently added '192.0.2.10' (ED25519) to the list of known hosts.The client stores the key in ~/.ssh/known_hosts (on Windows C:\Users\<naam>\.ssh\known_hosts). From now on it compares automatically with every connection. This model is called trust on first use (TOFU): the first time you have to check it yourself, after that the client keeps watch.
That is why the first check matters so much: if you trust the wrong key, the client will never warn you again.
If you work on a computer running Debian or Ubuntu yourself, the names in known_hosts are hashed by default (HashKnownHosts yes in /etc/ssh/ssh_config), so you will not see readable IP addresses there. On Windows and macOS they are stored in readable form. Searching works everywhere with:
anna@laptop:~$ ssh-keygen -F 192.0.2.10
# Host 192.0.2.10 found: line 3
|1|kP9...= ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA..."REMOTE HOST IDENTIFICATION HAS CHANGED"
Sometimes you see this warning:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
...
Host key verification failed.The server shows a different key from the one your client knows. ssh then refuses to connect. There are two kinds of causes:
| Normal | Suspicious |
|---|---|
| You reinstalled the VPS (new host keys) | You changed nothing and yet the key is different |
| The IP address has been given to another server | You are on an unfamiliar Wi-Fi network |
| You deliberately replaced the host keys | The fingerprint in the console differs from what the client sees now |
If there is a normal explanation, check the fingerprint in the console again and only then remove the old line:
anna@laptop:~$ ssh-keygen -R 192.0.2.10
# Host 192.0.2.10 found: line 3
/home/anna/.ssh/known_hosts updated.On the next connection you get the first-time question again, and you check again. Never set StrictHostKeyChecking no in your settings to get rid of the warning: that switches off exactly the protection that matters.
The version banner
Before anything is encrypted, client and server send each other a line of text: the version banner. Anyone on the internet can see it. You can view it with ssh -v:
anna@laptop:~$ ssh -v root@192.0.2.10 2>&1 | grep "remote software"
debug1: Remote protocol version 2.0, remote software version OpenSSH_9.6p1 Ubuntu-3ubuntu13.5Here the server says which protocol (2.0) and which software it uses. Debian and Ubuntu add the package version. That is not a secret you need to hide: attackers try everything anyway, and you protect yourself with updates (module 4), not with a different banner. It is useful, though: the banner shows you from the outside whether your server really runs the updated version.
On AlmaLinux and Rocky Linux
Logging in and fingerprints work the same way. The service is called sshd instead of ssh (systemctl status sshd). The banner contains no distribution name, only the OpenSSH version.
Summary
- SSH is the encrypted connection to your server;
sshis the client,sshdthe server on port 22. - On the first connection the client shows the fingerprint of the host key. Compare it with the output of
ssh-keygen -lfin the console before you typeyes. - The client stores the key in
~/.ssh/known_hostsand warns you itself from then on (trust on first use). - "REMOTE HOST IDENTIFICATION HAS CHANGED" is normal after a reinstall; otherwise it is suspicious. Only remove an old line after checking, with
ssh-keygen -R. - The version banner is public; protection comes from updates, not from hiding.
Quiz
Exercise
Exercise Z1.3: SSH banner and fingerprint of your server. Enter your server's address, the software version from the banner (such as OpenSSH_9.6p1) and the ED25519 fingerprint you looked up in the console with ssh-keygen -lf. The program makes one connection to your SSH port, reads the banner and the host key, and compares them. It does not log in.
Further reading
- Logging in to your VPS with SSH (and creating an SSH key)
- No access to your VPS anymore: what now?
- ssh-keygen(1), options -l, -F and -R: https://manpages.debian.org/trixie/openssh-client/ssh-keygen.1.en.html
- ssh_config(5), StrictHostKeyChecking, FingerprintHash and HashKnownHosts: https://manpages.debian.org/trixie/openssh-client/ssh_config.5.en.html
- RFC 4253, section 4.2 (the version banner): https://www.rfc-editor.org/rfc/rfc4253.html
