Module 2 · Services, SSH and Hardening · Lesson 7 of 10

SSH keys done safely

Create an ed25519 key pair, install only the public key, and prove a second login before changing anything else.

In this lesson · about 20 minutes

  • Explain public and private keys in SSH
  • Create and install a key, and check permissions
  • Change login settings without locking yourself out

Whiteboard · watch and try

Whiteboard: how the server knows it's you

Press Play. The tutor draws the laptop, the server and what travels between them.

5 steps
Press Play and the tutor will talk you through it while writing on the board. Pause any time to write on the board yourself.

Tip: press Pause, then use the pen to work along on the board. Space plays and pauses; Ctrl+Z undoes your last mark.

Try it · watch it happen

How an SSH key logs you in

Press Play to watch the key exchange. Then try the What if buttons.

Your laptop

Server

Step 1 of 7Your laptop wants to log in to the server. Passwords can be guessed, so we'll use a key pair instead.

What if…?

An SSH key pair has two halves:

  • The private key (~/.ssh/id_ed25519) stays on your computer. Anyone who has it can log in as you. Protect it with a passphrase and mode 600.
  • The public key (~/.ssh/id_ed25519.pub) can be shared freely. You copy it to the server's ~/.ssh/authorized_keys.

When you connect, the server challenges you to prove you hold the private key, without the key ever leaving your machine. Keys can't be guessed like passwords, which is why turning off password logins stops most SSH brute-force attacks.

The golden rule

Validate a second, working login before you disable any existing access method. Keep your current session open, open a new one with the key, and only then change PasswordAuthentication or PermitRootLogin.

Hands-on lab (simulated terminal)

Practice challenge 05: SSH keys

You're on your lab client. The lab server is 10.10.10.5 and your account there is learner.

Step 1 of 4. Type each command and press Enter. Nothing runs on your computer.

Practice challenge 05: SSH keys

1. Generate an ed25519 key pair.

learner@lab-client:~$

Check your understanding0 of 3 correct

Question 1

1.Which SSH key may be copied to a server?

Question 2

2.What should you do BEFORE setting PasswordAuthentication no?

Question 3

3.Key login fails and the server log says 'bad ownership or modes for directory /home/learner/.ssh'. What's the likely fix?

Quiz score: 0 of 3

Tip: answer every quiz question correctly first.

Noviq Academy is free and for learning. Every terminal here is simulated and every log is synthetic. Practise on a disposable VM with a snapshot, never on a production server. Ubuntu is a trademark of Canonical Ltd.; this course is independent of Canonical.