📑 Table of Contents

🎯 Lab Overview & What You Will Build

In this beginner-friendly lab, you will learn how to set up passwordless SSH authentication using cryptographic key pairs. You will generate your own public and private key pair, understand the difference between them, deploy your public key to a remote server, and establish a secure connection without ever typing a password. By the end of this lab, you will have mastered one of the most fundamental security skills in IT—the same technique used by system administrators, DevOps engineers, and cloud architects to securely access thousands of servers across enterprise environments.

👋 New to Linux or Command Line?

Don't worry! This lab is designed for absolute beginners. We explain every command, what it does, and why we're using it. Take your time, read each step carefully, and you'll build a solid foundation in secure authentication.

What You Will Build

Learning Objectives

🔑 Understanding SSH Key Authentication

Before we start generating keys, let's understand what SSH key authentication is and why it's more secure than passwords.

🧠 What is SSH?

SSH (Secure Shell) is a protocol that lets you securely connect to another computer over a network. When you "SSH into a server," you're establishing an encrypted connection that protects all data traveling between your computer and the server.

🏠 Real-World Analogy

Think of SSH like a secure phone call. Just as a phone encrypts your voice so others can't listen in, SSH encrypts your commands and data so hackers can't intercept them.

🔐 Password vs. Key Authentication

There are two main ways to prove your identity when connecting via SSH:

  • Password Authentication: You type a password. Simple, but passwords can be guessed, stolen, or brute-forced.
  • Key Authentication: You prove you own a cryptographic key. Much more secure—keys are nearly impossible to guess.
🏠 Real-World Analogy

Password = Telling the doorman a secret word (someone could overhear it). Key = Having a unique physical key that only fits your lock (nearly impossible to duplicate without the original).

🗝️ Public Key + Private Key = Key Pair

SSH key authentication uses asymmetric cryptography, which means you have TWO related keys:

  • Private Key (🔴 SECRET): Stays on YOUR computer. Never share it. Ever.
  • Public Key (🟢 SHAREABLE): Goes on any server you want to access. Safe to share.
🏠 Real-World Analogy

Think of a padlock (public key) and its key (private key). You can give the open padlock to anyone—they can lock things for you. But only YOU have the key to unlock it. In SSH, the server has your "padlock" (public key) and uses it to create a challenge that only your "key" (private key) can solve.

Why Keys Are More Secure Than Passwords

Factor Password SSH Key
Length 8-20 characters typical 2048-4096 bits (hundreds of characters)
Brute Force Can be guessed in hours/days Would take billions of years
Phishing Risk Can be stolen by fake login pages Private key never sent to server
Reuse Risk People often reuse passwords Unique key per device/purpose
Transmission Sent over network (encrypted) Never sent—only proof of ownership

🌍 Real-World Scenario & Skills Application

🏢 Enterprise Scenario: Your First Day as a Junior SysAdmin

Congratulations! You've just started as a Junior Systems Administrator at CloudScale Inc. On your first day, the senior admin hands you a laptop and says: "Here's your workstation. You'll need to access 15 Linux servers for monitoring and maintenance. First thing—set up your SSH keys. We don't allow password authentication on any production server."

This is a real scenario that happens every day in IT departments worldwide. The skills you learn in this lab directly translate to:

  • Server Administration: Securely accessing Linux/Unix servers for maintenance, updates, and troubleshooting
  • Cloud Infrastructure: Connecting to AWS EC2, Azure VMs, and Google Cloud instances (all use SSH keys)
  • DevOps Workflows: Enabling automated deployments where scripts SSH into servers
  • Git Operations: Pushing code to GitHub, GitLab, and Bitbucket (uses SSH keys)
  • Container Orchestration: Accessing Kubernetes nodes and debugging pod issues
  • Security Compliance: Meeting requirements that mandate key-based authentication over passwords

🎯 Skills You Will Gain & How They Apply

Cryptographic Key Management

Generate, store, and protect keys. Foundation for PKI, TLS certificates, and code signing.

Linux File Permissions

Set correct permissions on sensitive files. Critical for passing security audits.

Remote Server Access

Connect to any Linux server securely. Required for every sysadmin and DevOps role.

SSH Configuration

Create shortcuts and tune settings. Improves daily productivity dramatically.

Security Mindset

Understand why we protect private keys. Transfers to all security domains.

Troubleshooting Skills

Debug "Permission denied" errors. Highly valued in support and operations roles.

📋 Prerequisites & Requirements

💡 This Lab is Self-Contained

Unlike Labs 1 and 2, this lab does NOT require any previous labs. You can start fresh! All you need is a computer with a terminal.

What You Need

Requirement Options Notes
Computer Any modern computer Windows, macOS, or Linux
Terminal Access Built-in terminal Windows: PowerShell or WSL
macOS/Linux: Terminal app
Optional: Ubuntu VM VirtualBox or VMware For practicing SSH between machines

Hypervisor Options (Optional)

If you want to practice SSH between two machines, set up an Ubuntu VM using either:

Refer to Lab 1 for detailed VM installation instructions if needed.

Knowledge Prerequisites

🏗️ How SSH Keys Work (Visual Guide)

This diagram shows the relationship between your local machine, your key pair, and the remote server.

▼ SSH KEY AUTHENTICATION FLOW ▼

🔴
PRIVATE KEY

Stays on YOUR machine
NEVER share this
Used to prove identity

~/.ssh/id_ed25519
🟢
PUBLIC KEY

Copied to SERVER
Safe to share anywhere
Used to verify identity

~/.ssh/id_ed25519.pub
YOUR COMPUTER

Has private key
+ public key

➡️
SSH CONNECTION

Encrypted tunnel
Port 22

➡️
REMOTE SERVER

Has your public key
in authorized_keys

AUTHENTICATION STEPS
1. You run: ssh user@server 2. Server sends a random challenge (encrypted with YOUR public key) 3. Only YOUR private key can decrypt the challenge 4. Your computer sends back the decrypted answer 5. Server verifies → Access Granted! ✓

🔐 The Key Point (Pun Intended)

Your private key never leaves your computer. The server doesn't need your private key—it only needs your public key to create challenges. This is why key authentication is so secure!

🏷️ Environment Setup

Device Badges Legend

Code blocks in this lab are tagged with badges indicating where to run commands:

Local Machine Your personal computer (where you generate keys)
SSH Server The remote server you want to access
Ubuntu VM Optional VM for practice
1

Open Your Terminal

First, open a terminal on your computer. The terminal is where you'll type commands to generate and manage SSH keys. Don't worry if you've never used a terminal before—just follow along and type exactly what's shown.

How to open the terminal:

  • Windows 10/11: Press Win + X, then click "Windows Terminal" or "PowerShell"
  • macOS: Press Cmd + Space, type "Terminal", press Enter
  • Linux: Press Ctrl + Alt + T or search for "Terminal" in applications
2

Verify SSH is Installed

Check that SSH client software is installed on your computer. Most modern operating systems include SSH by default. Run the following command to verify:

Local Machine
ssh -V

Expected output: Something like OpenSSH_8.9p1 or OpenSSH_9.0. The exact version doesn't matter—if you see a version number, SSH is installed!

❓ Don't see a version number?

Windows: SSH is included in Windows 10 (1809+) and Windows 11. If missing, enable it in Settings → Apps → Optional Features → Add a feature → OpenSSH Client.

macOS/Linux: SSH is pre-installed. If somehow missing, run sudo apt install openssh-client (Linux) or reinstall Command Line Tools (macOS).

3

Check for Existing SSH Keys

Before generating new keys, let's check if you already have SSH keys. If you do, you might want to use them instead of creating new ones. Run this command to list any existing keys:

Local Machine
ls -la ~/.ssh/

If you see files like:

  • id_rsa and id_rsa.pub — You have RSA keys
  • id_ed25519 and id_ed25519.pub — You have Ed25519 keys (modern)
  • No such file or directory — No keys yet, we'll create them!

🔑 Generating SSH Key Pairs

Now we'll create your personal SSH key pair. We'll use the Ed25519 algorithm, which is modern, secure, and creates smaller keys than the older RSA algorithm.

4

Generate an Ed25519 Key Pair

Run the following command to generate a new Ed25519 SSH key pair. The -C flag adds a comment (usually your email) to help identify the key later. Replace the email with your own.

Local Machine
ssh-keygen -t ed25519 -C "your.email@example.com"

You'll be prompted with three questions:

  1. "Enter file in which to save the key" — Press Enter to accept the default location (~/.ssh/id_ed25519)
  2. "Enter passphrase" — Type a strong passphrase (recommended) or press Enter for no passphrase
  3. "Enter same passphrase again" — Confirm your passphrase

🔒 Should I Use a Passphrase?

Yes, for maximum security! A passphrase encrypts your private key so that even if someone steals the file, they can't use it without the passphrase. Think of it as a password for your key.

For this lab, you can skip the passphrase (just press Enter) for simplicity. But in production, always use a strong passphrase!

5

Verify Your Keys Were Created

After generating the keys, verify that both files were created successfully. You should see two new files in your .ssh directory.

Local Machine
ls -la ~/.ssh/

Expected output: You should see:

  • id_ed25519 — Your private key (permissions should be -rw------- or 600)
  • id_ed25519.pub — Your public key (permissions can be more open)
6

View Your Public Key

Let's look at your public key. This is the key you'll share with servers. It's a single long line of text that starts with ssh-ed25519.

Local Machine
cat ~/.ssh/id_ed25519.pub

Example output:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... your.email@example.com

✅ This is Safe to Share!

Your public key is designed to be shared. You can email it, paste it into websites (like GitHub), or add it to any server. It cannot be used to impersonate you—only your private key can do that.

7

Understand Your Private Key (DO NOT SHARE)

Your private key is stored in ~/.ssh/id_ed25519 (no .pub extension). Let's verify its permissions are secure. The private key should only be readable by you (owner).

Local Machine
ls -la ~/.ssh/id_ed25519

Expected output: -rw------- — This means only you (the owner) can read and write the file. No one else on the system can access it.

⚠️ NEVER Share Your Private Key!

Your private key is like your house key. Never email it, paste it into websites, commit it to Git, or show it to anyone. If compromised, someone could access all servers that trust your public key.

📤 Deploying Public Keys

Now that you have your key pair, you need to put your public key on the servers you want to access. There are several ways to do this.

8

Method 1: Using ssh-copy-id (Easiest)

The ssh-copy-id command automatically copies your public key to a remote server and sets up the correct permissions. This is the easiest method when you have password access to the server.

Replace username with your username on the remote server, and server-ip with the server's IP address or hostname.

Local Machine
ssh-copy-id username@server-ip

Example: ssh-copy-id john@192.168.1.100

You'll be prompted for the server password (this is the last time you'll need it!). After success, you'll see:

Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'username@server-ip'" and check to make sure that only the key(s) you wanted were added.
9

Method 2: Manual Copy (When ssh-copy-id Unavailable)

If ssh-copy-id isn't available (common on Windows without WSL), you can manually copy your public key. First, display your public key and copy it to your clipboard:

Local Machine
cat ~/.ssh/id_ed25519.pub

Select and copy the entire output (one long line starting with ssh-ed25519).

Then, SSH into the server using password authentication:

Local Machine
ssh username@server-ip

Once logged into the server, add your public key to the authorized_keys file:

SSH Server
mkdir -p ~/.ssh chmod 700 ~/.ssh echo "PASTE_YOUR_PUBLIC_KEY_HERE" >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys

Replace PASTE_YOUR_PUBLIC_KEY_HERE with the public key you copied earlier.

10

Practice: Set Up SSH to Localhost (No Server Needed)

Don't have a remote server? You can practice SSH key authentication by connecting to your own computer! First, ensure the SSH server is running on your machine:

Ubuntu VM or Linux
sudo apt update sudo apt install -y openssh-server sudo systemctl enable ssh sudo systemctl start ssh

Then copy your key to localhost:

Ubuntu VM or Linux
ssh-copy-id $USER@localhost

Enter your user password when prompted. Now you can SSH to yourself without a password!

✅ Testing SSH Connection

11

Connect Using SSH Key Authentication

Now test your passwordless SSH connection! Connect to the server where you deployed your public key. If everything is set up correctly, you'll log in without being asked for a password.

Local Machine
ssh username@server-ip

Success indicators:

  • You're logged in immediately (no password prompt)
  • If you set a passphrase on your key, you'll be asked for that instead
  • You see the server's command prompt

🎉 Congratulations!

If you're logged in without entering a password, you've successfully set up SSH key authentication! This is how professionals access servers securely.

12

Verbose Mode for Debugging

If SSH isn't working as expected, use verbose mode to see exactly what's happening during the connection. The -v flag shows detailed debug information.

Local Machine
ssh -v username@server-ip

Look for lines containing:

  • Offering public key — SSH is trying your key
  • Server accepts key — Key authentication succeeded!
  • Permission denied — Key rejected (check permissions)

⚙️ SSH Configuration File

The SSH config file lets you create shortcuts for servers, specify which key to use, and customize connection settings. This makes your life much easier when managing multiple servers.

13

Create SSH Config File

Create or edit the SSH configuration file in your .ssh directory. This file defines how SSH connects to different hosts.

Local Machine
nano ~/.ssh/config

Add configuration blocks for your servers. Here's an example:

# Default settings for all hosts Host * AddKeysToAgent yes IdentitiesOnly yes # Production web server Host webserver HostName 192.168.1.100 User admin IdentityFile ~/.ssh/id_ed25519 Port 22 # Development server Host devbox HostName dev.example.com User developer IdentityFile ~/.ssh/id_ed25519 Port 2222 # Local VM for testing Host labvm HostName localhost User iamstudent IdentityFile ~/.ssh/id_ed25519

Save the file: Press Ctrl + O, then Enter, then Ctrl + X to exit nano.

14

Set Config File Permissions

The SSH config file must have restrictive permissions to be used. Set the correct permissions:

Local Machine
chmod 600 ~/.ssh/config
15

Use SSH Config Shortcuts

Now instead of typing the full SSH command with all options, you can simply use the shortcut name you defined:

Local Machine
# Instead of: ssh admin@192.168.1.100 ssh webserver # Instead of: ssh developer@dev.example.com -p 2222 ssh devbox # Instead of: ssh iamstudent@localhost ssh labvm

Much simpler! The config file handles all the details for you.

🔒 Security Best Practices

16

Verify File Permissions

SSH is very strict about file permissions. If permissions are too open, SSH will refuse to use your keys. Run this command to verify and fix permissions:

Local Machine
# Set correct permissions chmod 700 ~/.ssh chmod 600 ~/.ssh/id_ed25519 chmod 644 ~/.ssh/id_ed25519.pub chmod 600 ~/.ssh/config chmod 600 ~/.ssh/authorized_keys 2>/dev/null # Verify permissions ls -la ~/.ssh/

Correct permissions:

  • ~/.ssh/ directory: drwx------ (700)
  • id_ed25519 (private key): -rw------- (600)
  • id_ed25519.pub (public key): -rw-r--r-- (644)
  • config: -rw------- (600)
  • authorized_keys: -rw------- (600)

Security Checklist

🛡️ Protect Your SSH Keys

  • Use a passphrase on your private key (especially on shared or portable computers)
  • Never share your private key file with anyone
  • Never commit private keys to Git repositories
  • Use different keys for different purposes (personal, work, servers)
  • Rotate keys periodically (annually or when compromised)
  • Remove old keys from servers when no longer needed
  • Backup keys securely (encrypted storage)

🔧 Troubleshooting Guide

Common Issues and Solutions

Issue: "Permission denied (publickey)"

Cause: Server doesn't have your public key or permissions are wrong

Solutions:

  • Verify public key is in server's ~/.ssh/authorized_keys
  • Check authorized_keys permissions: chmod 600 ~/.ssh/authorized_keys
  • Check .ssh directory permissions: chmod 700 ~/.ssh
  • Use ssh -v to see which keys are being tried

Issue: "Bad permissions" or "Key ignored"

Cause: Private key file permissions are too open

Solution: Fix permissions on your local machine:

chmod 600 ~/.ssh/id_ed25519

Issue: SSH still asks for password

Causes and solutions:

  • Wrong key being used → Specify key explicitly: ssh -i ~/.ssh/id_ed25519 user@server
  • Key not in authorized_keys → Re-run ssh-copy-id
  • Server configured to require password → Check /etc/ssh/sshd_config

Issue: "Connection refused"

Cause: SSH server not running or firewall blocking

Solutions:

  • On server: sudo systemctl status ssh
  • Start SSH: sudo systemctl start ssh
  • Check firewall: sudo ufw allow 22

🧹 Cleanup & Reset

17

Remove Keys (If Needed)

If you want to start fresh or remove test keys, here's how to clean up. Be careful—deleting keys means losing access to any server that only has those public keys!

Local Machine
# Remove test keys (CAREFUL - this deletes your keys!) rm ~/.ssh/id_ed25519 rm ~/.ssh/id_ed25519.pub # Remove SSH config (optional) rm ~/.ssh/config # On server: Remove a specific public key from authorized_keys # Edit the file and delete the line containing your public key nano ~/.ssh/authorized_keys

🎓 Key Takeaways

Skills Mastered in This Lab

Key Concepts to Remember

Next Labs in the Series

📚 Additional Learning Resources

Continue your SSH and cryptography learning journey with these resources:

📖 Official Documentation
🎓 Tutorials & Courses
🔧 Tools & Utilities
📚 Books
  • SSH Mastery — Michael W Lucas
  • Practical Cryptography for Developers — Free online book
  • Linux Command Line and Shell Scripting Bible — Richard Blum
🔐 Security Resources

💡 Practice Recommendations

  • Set up GitHub SSH: Add your public key to GitHub and practice git push without passwords
  • Create multiple keys: Generate separate keys for work and personal use
  • Try SSH agent: Learn ssh-agent to avoid re-entering passphrases
  • Set up a cloud VM: Create a free-tier AWS, Azure, or GCP instance and SSH into it
  • Harden SSH: Configure /etc/ssh/sshd_config to disable password authentication
  • Explore SSH tunneling: Learn port forwarding and SOCKS proxies