Skip to content

Cookie settings

Choose which kinds of cookies you allow. You can change your choice at any time via Cookie settings at the bottom of every page. Privacy statement

Necessary

Always on

Needed to log in, keep your cart and remember your choices. These are always on.

Which cookies?
  • weboke_sessie, weboke_klant, weboke_remember: your session and staying logged in
  • weboke_basket: your cart
  • wkBtwIncl: showing prices with or without VAT
  • wok_cookies: your cookie choice, 12 months

Measures which ad leads to a visit or order, so we do not pay for ads that do nothing.

Which cookies?
  • Google Ads via Google Tag Manager (_gcl_au, _gcl_aw), up to 90 days
  • OpenAI Ads, ads in ChatGPT
  • wok_aff: which partner referred you to us (affiliate programme), 60 days

4.6

Country and language

Each country has its own site, with prices and VAT for that country.

View

Module 1 · 1.3

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 use ssh.
  • 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.10

Or with a name, if you have set one up in DNS (lesson 7.1):

anna@laptop:~$ ssh root@web1.example.com

The 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:

NormalSuspicious
You reinstalled the VPS (new host keys)You changed nothing and yet the key is different
The IP address has been given to another serverYou are on an unfamiliar Wi-Fi network
You deliberately replaced the host keysThe 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.5

Here 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; ssh is the client, sshd the 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 -lf in the console before you type yes.
  • The client stores the key in ~/.ssh/known_hosts and 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

1. What do you compare the fingerprint that ssh shows on the first connection with?



2. What does ~/.ssh/known_hosts do?



3. You reinstalled your VPS and get "REMOTE HOST IDENTIFICATION HAS CHANGED". What is the right order?



4. Why is the first check so important with trust on first use?



5. What does the version banner of an SSH server show?



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.

Exercise Z1.3: SSH banner and fingerprint of your server

We don't log in and we don't try any password or key. First you show that the server is yours: click "Show my code" and place a file /.well-known/weboke-cursus-<code>.txt containing only that code on the web server of your hostname. We fetch it directly from each IP address we check (IPv4 and IPv6 separately); a TXT record doesn't count here. The check comes from heavy.webawere.nl (185.158.167.16 and 2a07:ae80:100:0:185:158:167:16), not from our web server. Only for registered students; at most 6 checks per server per hour. For this exercise we make one connection and only read the server's banner and key; no login attempt will appear in your log.





What you enter and what we find isn't stored. Your browser remembers your answers and whether you've passed the exercise. If you're signed in, we only save that you got the exercise (almost) right in My courses; you can delete that there too.

Further reading

One moment…

Set up your domains

For each domain, arrange the nameservers, the link to your hosting and who becomes the owner.

Loading your domains…