0:00–0:10
Recap
0:10–0:40
Lecture
0:40–1:50
Lab 1C Parts 1–2
1:50–2:00
Debrief
0:00 – 0:10
Recap · 10 min
Verify network and motivate SSH keys
- Verify all three VMs are reachable. Quick check: from Windows host, SSH to each server using password auth — just confirm connectivity. Ask: "How would an attacker try to get into these servers right now?" — password guessing. The default SSH port (22) is scanned by bots continuously. A server with password auth enabled on port 22 is already being attacked. Today we address that.
- Ask: "In NETW-0001 you worked with SSH. What's the difference between SSH with a password and SSH with a key?" — take answers and use them to frame the lecture. Students who remember the concept well will explain the basics; the lecture formalises and deepens it.
0:10 – 0:40
Lecture · 30 min
Asymmetric cryptography, the SSH key auth handshake, and why keys beat passwords
Part 1 — Symmetric vs. asymmetric encryption (8 min)
- Symmetric encryption: One key encrypts and decrypts. Both parties must have the same key. The problem: how do you securely share the key in the first place? If you could securely send the key, you probably didn't need encryption to start with. Good for bulk data (AES), but has a key distribution problem.
- Asymmetric encryption: Two mathematically linked keys — a public key and a private key. Anything encrypted with the public key can only be decrypted with the private key. Anything signed with the private key can be verified with the public key. The public key can be shared openly — there's no risk in publishing it. The private key never leaves the machine that owns it.
- Analogy: a padlock and its key. You hand out padlocks (public keys) to anyone who wants to send you a locked box. Only you have the key (private key) that opens them. Anyone can lock a box for you — only you can open it.
- RSA: one of the oldest and most widely-used asymmetric algorithms. Key strength is measured in bits — the larger the key, the more computationally expensive to break. 2048-bit was once the standard; 4096-bit is the current recommendation for long-lived keys. The computational cost to generate or use a 4096-bit key is trivial on modern hardware.
Part 2 — The SSH key authentication handshake (12 min)
- Walk through what happens when you SSH with a key — draw this on the board step by step:
1. Client connects to server, announces its public key identity
2. Server checks ~/.ssh/authorized_keys — is this public key listed?
3. If yes: server generates a random challenge and encrypts it with the client's public key
4. Client decrypts the challenge using its private key, sends back proof
5. Server verifies the proof — only the holder of the matching private key could have produced it
6. Connection established — no password ever sent over the wire
- Ask: "Why is this stronger than a password?" Build the list together:
· The private key never travels over the network — there's nothing to intercept
· Even if someone captures every byte of the SSH session, they can't extract the key
· A 4096-bit private key is effectively impossible to brute force — a good password might be 12 characters; that's far weaker
· No server-side password storage — there's no hashed password database to steal
- The two files:
id_rsa — the private key. Never copy this to any server. Never email it. Never share it. Treat it like a physical key to your building. id_rsa.pub — the public key. This is what you copy to servers. Safe to send by email, post on a website, or put on a USB drive. It's useless without the private key.
- File locations: On Windows, ssh-keygen stores keys in
C:\Users\[username]\.ssh\. On Linux servers, each user's authorised public keys are in ~/.ssh/authorized_keys. The .ssh directory must be mode 700, and authorized_keys must be mode 600 — SSH is strict about this and will silently ignore keys with wrong permissions.
Part 3 — Key passphrases and agent forwarding (10 min)
- Passphrases: When generating a key,
ssh-keygen offers to encrypt the private key file with a passphrase. This adds a second factor — even if someone steals the key file, they can't use it without the passphrase. For this course we skip the passphrase (simpler for lab work), but in production, a passphrase is strongly recommended.
- SSH agent: If you use a passphrase, you'd have to type it every time you connect — annoying. The SSH agent is a background process that holds your decrypted private key in memory for the session.
ssh-add loads the key into the agent; after that, connections use the agent without prompting again. Windows OpenSSH includes an agent service.
- Why we use 4096 bits specifically: 2048-bit RSA keys are still considered secure today, but key generation is cheap and storage is trivial. There is no practical reason not to use 4096 bits. Some organisations mandate 4096-bit as policy. The habit of using the stronger key is worth building.
Instructor note: The handshake walkthrough on the board (Part 2) is the most valuable part of this lecture. Don't rush it. Students who understand the handshake intuitively are much better at debugging key auth failures later — they know what to check and why each piece matters.
0:40 – 1:50
Lab 1C Parts 1–2 · 70 min
Generate SSH keys on Windows, install openssh-server on all VMs, distribute public keys via SCP
Part 1 — Generate SSH keys on Windows host (15 min)
- Open Windows PowerShell or Command Prompt on the host PC. Generate a 4096-bit RSA key pair:
ssh-keygen -t rsa -b 4096
Accept the default file location (C:\Users\Student\.ssh\id_rsa). When prompted for a passphrase, press Enter twice to skip it for this course.
- Identify the two files created. Navigate to
C:\Users\Student\.ssh\ in File Explorer or list with dir C:\Users\Student\.ssh\. Confirm both files exist. Record the exact filenames in your lab sheet. Ask: which file gets copied to the servers? (The .pub file only.)
- Display the public key content:
type C:\Users\Student\.ssh\id_rsa.pub. It begins with ssh-rsa AAAA... and ends with a comment. This entire string is what gets placed in authorized_keys on each server.
Part 2 — Verify SSH access and install openssh-server (10 min)
- Verify openssh-server is installed on all three VMs (it was selected during install). Check:
sudo systemctl status ssh. If not running: sudo apt install openssh-server, then sudo systemctl enable --now ssh.
- Test password-based SSH from Windows to each server:
ssh student@[S1-IP]
Accept the host key fingerprint (type yes). Log in with password Room225. This confirms the baseline before we add key auth.
Part 3 — Copy public key to all three servers (25 min)
- The cleanest method on Windows is
ssh-copy-id, but it requires a Unix-style SSH client. The manual method works everywhere:
Step 1 — on the Windows host, display the public key: type C:\Users\Student\.ssh\id_rsa.pub
Step 2 — SSH into S1 with password. Create the .ssh directory and set permissions:
mkdir -p ~/.ssh && chmod 700 ~/.ssh
Step 3 — open (or create) the authorized_keys file: nano ~/.ssh/authorized_keys
Step 4 — paste the public key content (the full ssh-rsa AAAA... line). Save and exit.
Step 5 — set permissions: chmod 600 ~/.ssh/authorized_keys
- Alternatively, use SCP to copy the public key file directly:
scp C:\Users\Student\.ssh\id_rsa.pub student@[S1-IP]:~/.ssh/authorized_keys
Then SSH to S1 and set permissions: chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys
- Repeat for S2 and S3. All three servers should end up with the same public key in
~/.ssh/authorized_keys — because they all need to accept connections from the same Windows host.
Part 4 — Test key-based login and create Windows Terminal sessions (20 min)
- Test from Windows host — you should connect without entering a password:
ssh student@[S1-IP]
If it still asks for a password, key auth is not working — check permissions on ~/.ssh (must be 700) and ~/.ssh/authorized_keys (must be 600). Check the server's /var/log/auth.log for the specific error.
- Verify key auth on S2 and S3 in the same way. All three connections should be passwordless before moving on.
- Create named sessions in Windows Terminal for fast access: open Windows Terminal → Settings → Add a new profile for each server. Name them S1, S2, S3. Set the command line for each:
ssh student@[IP]. You can now open a terminal directly to any server with one click.
Common mistake: Students often copy the private key (id_rsa) instead of the public key (id_rsa.pub). If a student's key auth fails and they've confirmed the permissions are correct, check the content of authorized_keys — it should start with ssh-rsa, not -----BEGIN OPENSSH PRIVATE KEY-----.
1:50 – 2:00
Debrief · 10 min
Verify key auth and preview Day 4
- Show of hands: who has passwordless SSH to all three servers? Anyone still with password prompts — what error are they seeing? Walk through the three most common causes live: wrong file copied, wrong permissions, wrong file path.
- Ask: "We have key auth working. But password auth is still enabled on these servers — we haven't disabled it. Why is that a problem?" — an attacker can still brute-force passwords even if we personally use keys. Tomorrow: disable password auth entirely, and add several more hardening steps.
- Preview Day 4:
sshd_config — the SSH daemon configuration file. We will work through it line by line and apply production-grade settings. Students should read the lab sheet for Day 4 tonight if time allows.
Learning outcomes — by end of Day 3, students can…
Explain asymmetric encryptionDescribe the relationship between public and private keys, and explain why the public key can be shared freely
Describe the SSH key handshakeWalk through the five-step authentication flow without referring to notes
Generate an SSH key pairUse ssh-keygen to produce a 4096-bit RSA key pair and identify the correct file to distribute
Deploy key authenticationCopy a public key to a server's authorized_keys file, set correct permissions, and verify passwordless login
Configure Windows Terminal sessionsCreate named SSH profiles for rapid server access
Common issues and fixes
| Issue | Likely cause | Fix |
| SSH still prompts for password after key copy | Permissions wrong on ~/.ssh or authorized_keys | On the server: chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys. Check ownership: ls -la ~/.ssh — both must be owned by student |
| authorized_keys exists but key auth fails | Private key copied instead of public key | Check file content: cat ~/.ssh/authorized_keys. Should start with ssh-rsa AAAA. If it starts with -----BEGIN, delete the file and copy the .pub file instead |
| SCP command fails with "No such file or directory" | Windows path format incorrect, or .ssh directory doesn't exist on server | Create ~/.ssh first via SSH: mkdir -p ~/.ssh. Use forward slashes in Windows SCP paths or quote the path |
| SSH asks to verify host fingerprint every time | Known_hosts file not being written, or different IP used each time | Normal behaviour on first connection only. If it repeats, check that the Windows .ssh directory is writable by the Student user |