🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Web & Software Development › Linux/Bash for Web & Software Development › Lesson 10
TEC-WEB46-06 · Lesson 10 · 14 clock hours · lab

SSH, Remote Access, and Key-Based Authentication

Objective. Students will generate SSH key pairs, configure key-based login to a remote Linux host, harden the SSH daemon configuration, and use SCP and rsync for secure file transfer.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

Why SSH Matters for Web Developers

Secure Shell (SSH) is the standard protocol for remotely administering Linux servers, pushing code, and transferring files. Every web and software developer who works with a cloud server, a VPS, or a co-located machine will use SSH daily. Understanding how to configure it securely is not optional — a misconfigured SSH server is one of the most common entry points for unauthorized access.

How SSH Authentication Works

SSH supports two main authentication methods: password-based and key-based. Password authentication is convenient but vulnerable to brute-force attacks. Key-based authentication uses a mathematically linked pair of files:

When you connect, the server sends a challenge that only the holder of the matching private key can answer. Even if an attacker captures network traffic, they cannot derive the private key from the public key.

Generating an Ed25519 Key Pair

Ed25519 is the recommended algorithm today. It produces shorter keys than RSA while providing strong security. To generate a key pair:

```bash

ssh-keygen -t ed25519

```

The tool asks for a save location (accept the default `~/.ssh/id_ed25519`) and a passphrase. Always set a passphrase. If your private key file is ever stolen, the passphrase is the last line of defense preventing its use. Your private key file should have permissions `600` (owner read/write only). The `.ssh` directory itself should be `700`. These permissions are set automatically by `ssh-keygen`, but verify them:

```bash

ls -la ~/.ssh/

```

Copying the Public Key to a Remote Host

`ssh-copy-id` is the safest, easiest way to install your public key on a remote server:

```bash

ssh-copy-id username@remote_ip

```

This appends your public key to the remote user's `~/.ssh/authorized_keys` and sets correct permissions. After this step, test the connection:

```bash

ssh username@remote_ip

```

You should be prompted for your local passphrase (not the remote password), and you should log in successfully.

Hardening the SSH Daemon (sshd_config)

The SSH daemon configuration file is `/etc/ssh/sshd_config`. Editing it incorrectly can lock you out of a server, so always keep a second terminal session open while making changes, and test before closing that session.

Three essential hardening settings:

| Directive | Recommended Value | Reason |

|---|---|---|

| `PermitRootLogin` | `no` | Prevents direct root login over SSH |

| `PasswordAuthentication` | `no` | Forces key-based auth only |

| `Port` | A non-default value | Reduces automated scanning noise |

After editing, reload the daemon without dropping existing connections:

```bash

sudo systemctl reload sshd

```

Then verify from a new terminal window that key-based login still works before closing your existing session.

Safety note: Disabling `PasswordAuthentication` before confirming your key-based login works will lock you out of the server. Always test in order: (1) confirm key login works, (2) then disable password auth, (3) then reload, (4) then test again from a new session.

Secure File Transfer: SCP and Rsync

SCP (Secure Copy Protocol) copies files over SSH. To push a local archive to a remote server:

```bash

scp project.tar.gz username@remote_ip:/home/username/

```

SCP is simple but copies the entire file every time, even if only one byte changed.

Rsync is smarter. It calculates differences and transfers only changed blocks. The `--checksum` flag compares files by MD5/SHA checksum rather than modification time and file size, which is more reliable:

```bash

rsync -av --checksum local_dir/ username@remote_ip:/home/username/remote_dir/

```

Flags used:

After syncing, compare directory sizes on both machines with:

```bash

du -sh directory_name/

```

If both values match, the transfer was accurate.

Credential Relevance

This lesson directly supports the CompTIA Linux+ exam, which tests SSH configuration, file permissions, and secure remote access. CompTIA ITF+ concepts of networking and security fundamentals underpin the theory. PCEP Python is less directly tested here, but Python scripts often automate SSH tasks using libraries like Paramiko.

Key Safety Rules Summary

1. Never share your private key.

2. Always use a passphrase on private keys.

3. Keep a live session open when editing `sshd_config`.

4. Test key login before disabling password auth.

5. Verify file permissions on `~/.ssh/` are `700` and on private key files are `600`.

Key terms9

SSH (Secure Shell)A cryptographic network protocol for securely operating network services, most commonly used for remote command-line login and file transfer on Linux systems.
Key pairA matched set of cryptographic files — a private key kept secret on the local machine and a public key installed on the remote server — used together for authentication.
Ed25519A modern elliptic-curve algorithm supported by OpenSSH that generates compact, high-security SSH key pairs and is the currently recommended choice over older RSA keys.
authorized_keysA file located at ~/.ssh/authorized_keys on the remote server that lists public keys permitted to log in to that user account without a password.
sshd_configThe main configuration file for the OpenSSH daemon, located at /etc/ssh/sshd_config, where directives such as PermitRootLogin and PasswordAuthentication are set.
SCP (Secure Copy Protocol)A command-line utility that copies files between hosts over an SSH connection, encrypting both authentication and data in transit.
rsyncA file synchronization and transfer utility that efficiently copies only changed data between source and destination, and can operate securely over SSH.
PassphraseA secret phrase used to encrypt a private key file on disk, providing a second layer of protection if the key file is stolen.
PermitRootLoginAn sshd_config directive that controls whether the root account can authenticate directly over SSH; setting it to 'no' is a standard hardening practice.
In class: Key generation lab: students run 'ssh-keygen -t ed25519' with a passphrase, copy the public key to a partner's VM using ssh-copy-id, and confirm passwordless login works before and after disabling password authentication in sshd_config. · SSH hardening walkthrough: instructor demonstrates setting 'PermitRootLogin no', 'PasswordAuthentication no', and a custom port in /etc/ssh/sshd_config; students implement each change, reload sshd, and verify the daemon is still reachable. · File transfer exercise: students use scp to push a project archive to the remote VM and rsync with --checksum to synchronize a local directory, then compare sizes with 'du -sh' to confirm accuracy.
Materials: Pairs of student VMs on the same LAN, OpenSSH man pages, sshd_config reference, rsync man page
Check: Instructor attempts password login to each student's VM (must be refused) and key-based login (must succeed); rsync output must show zero files skipped — pass requires both outcomes confirmed.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

Security fundamentals / Linux+ Security
1. A student runs 'ssh-keygen -t ed25519' and is prompted for a passphrase. What is the primary security purpose of setting a passphrase?
Linux+ / Remote access and SSH
2. Which command correctly copies a local public key to a remote server's authorized_keys file?
Linux+ / System services and daemons
3. After editing /etc/ssh/sshd_config, a student wants to apply changes without dropping active SSH connections. Which command is correct?
Linux+ / Security hardening
4. An instructor sets 'PasswordAuthentication no' in sshd_config and reloads sshd, but a student forgot to copy their public key first. What will happen when the student tries to connect?
Linux+ / File permissions
5. What is the correct permission setting for a private SSH key file such as ~/.ssh/id_ed25519?
Linux+ / File management and transfer
6. A developer uses 'rsync -av --checksum local_dir/ user@server:/remote_dir/' to sync files. What does the --checksum flag specifically do?
Linux+ / Security hardening
7. Which of the following sshd_config settings is a recommended hardening practice to reduce automated brute-force scanning?
ITF+ / Security concepts
8. Which concept from CompTIA ITF+ best describes why key-based SSH authentication is more secure than password authentication?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.