Skip to content

Keys Only Login

You'll log in to your server with a key instead of a password, turn password logins off, and get the lockout trap out of the way while a second window is still open.

About

Every box in the lab gets reached over SSH, and a password you type is the weakest part of it. A key pair takes a minute to make, lets you log in from your laptop without typing anything, and means nobody can guess their way in. The trap is closing your only session before you've tested the key, and then you're walking over with a keyboard, so keep one terminal logged in until the new way works. This is an evening, and it's the first thing to do on every machine from now on.

At a glance

Per requirement
15 XP
Completion bonus
75 XP
Requirements
5
Takes
One evening
Skill level
Beginner (done it a few times)
Cost
Free
Supplies
You need some
Where
At home
Other people
On your own

Requirements

  1. 1
    Make a key pair on your laptop with a passphrase on it. Run ssh-keygen with the ed25519 type and give it a passphrase, so a stolen laptop isn't a stolen server. The private key never leaves the laptop, and the .pub file is the one you hand out. Take a screenshot of the fingerprint from ssh-keygen -lf and the two files listed, never the private key's contents. Photo
  2. 2
    Put the public key on the server and log in without typing a password. ssh-copy-id does it in one line. Open a second terminal and log in. If it still asks for a password, the usual reason is permissions: the .ssh folder wants 700 and authorized_keys wants 600. Film the login going straight to a prompt. Video
  3. 3
    Turn off password logins, then test from a fresh window before you close the old one. In sshd_config set PasswordAuthentication to no and PermitRootLogin to no, then reload sshd. From a new window, try a login with the key switched off (ssh -o PubkeyAuthentication=no) and watch it refuse, then a normal one that works. Keep the old session open the whole time. Take a screenshot of the refusal next to the successful login. Photo
  4. 4
    Give every box a short name in your ssh config. A Host block with the hostname, the user and the key file means you type ssh pi instead of the whole address. Add every machine in the lab while you're there. Take a screenshot of the config and a login by the short name. Photo
  5. 5
    Add a second device with its own key, then take its key away. Your phone with an SSH app, or a second laptop. Each device gets its own key pair rather than a copy, so you can drop one without touching the others. Log in from it, then delete its line from authorized_keys and watch it get refused. Film the phone logging in and then being turned away after you remove its key. Video