LAB-SEC-03 - SSH Key Authentication
Generate an SSH key pair, authorize the public key, and verify key-based login before changing server authentication settings.
SSH Key Authentication
Generate an SSH key pair, authorize the public key, and verify key-based login before changing server authentication settings.
- Generate an SSH key pair, authorize the public key, and verify key-based login before changing server authentication settings.
- Repeat the workflow without copy-paste or step-by-step prompting.
- Treat security and firewall changes as high impact and validate that you still have a recovery path before applying them.
Part A: The Field Guide
What This Lab Is Really About
SSH keys improve remote access because they replace reusable passwords with a stronger authentication mechanism.
The main habits are:
- generate the pair safely
- keep the private key private
- place the public key where the server expects it
- test the login before making SSH stricter
Command Reference
ssh-keygen -t ed25519 -C "practice_key" ssh-copy-id -i ./custom_key.pub localhost ssh -i ./custom_key localhost
Part B: The Drill Deck
Terminal required: use a local or disposable environment for the first practice.
G Guided Step by step - type exactly this and compare the result >
Exercise G1: Generate a Practice Key Pair
- Go to your home directory:
cd ~ - Generate a key pair:
ssh-keygen -t ed25519 -C "dojo_practice_key"- When asked where to save it, do not overwrite your normal key. Save it as:
./custom_key- Complete the prompts.
Exercise G2: Inspect the Pair Safely
- List the files:
ls -l custom_key*-
Confirm that you have:
- a private key file
- a
.pubpublic key file
-
Read only the public key file if you want to inspect the format:
cat custom_key.pubExercise G3: Authorize the Public Key
- In a local practice setup, copy the public key to
localhost:
ssh-copy-id -i ./custom_key.pub localhost- Follow the prompts.
- Confirm that the key was added successfully.
S Solo Task described, hints available - figure it out >
Exercise S1: Test Key-Based Login
- Log into localhost with the specific key:
ssh -i ./custom_key localhost- Confirm that the login works.
- Exit back to your normal shell.
Exercise S2: Inspect the Authorization File
- Read the authorized-keys file:
cat ~/.ssh/authorized_keys- Confirm that your public key was added.
M Mission Real scenario - no hints, combine multiple skills >
Mission M1: Explain the Safe Hardening Order
Imagine you are about to set PasswordAuthentication no on a real server.
Write down the safe order:
- generate or obtain the key pair
- place the public key on the server
- test key login in a separate session
- only then change SSH authentication settings
If you can explain why that order prevents lockout, the mission is complete.
What to do next
Best next step LearningReturn to the related lesson if you want the concept explained more deeply.