Chapter 20. Secure Remote Administration with SSH

Almost everything an administrator does to a remote Debian system - logging in, editing configuration, copying files, deploying software, reaching a service that has no other exposure - travels through SSH. This chapter treats it as an operational whole: installing and running the OpenSSH server, managing user authentication with keys and agents, scaling key management with SSH certificates, restricting what a server accepts, keeping client-side connections organized, and diagnosing the authentication and host-key failures that every administrator eventually meets.

The examples run on three Debian 13 machines connected by two isolated practice networks, with a third network held in reserve:

Host Role Practice interfaces Administration
sshadmin john's workstation; the SSH client for every exercise eth1 - work network, 192.168.220.10/24 eth0 192.168.121.208/24
sshjump jump host; one leg on each practice network eth1 - work network, 192.168.220.30/24; eth2 - internal network, 192.168.221.30/24 eth0 192.168.121.53/24
sshserver the host being administered eth1 - internal network, 192.168.221.20/24 eth0 192.168.121.108/24

The chapter 20 practice network

Figure 20.1. Two isolated practice networks carry every SSH exercise. sshadmin cannot reach the internal network directly; connections to sshserver go through sshjump. The administration network is deliberately left out of the exercises so it stays available as a lifeline when a policy change goes wrong.

That topology is not an accident of the lab: it is the shape real networks take. The internal network plays the role of a server segment a workstation cannot reach, sshjump the only host allowed to relay into it, and the administration network the out-of-band channel a site keeps for the day SSH policy itself is the problem. Section 20.4.4 leans on exactly that separation, and every disruptive exercise in this chapter runs against a second sshd instance on a separate port so that a mistake never costs the working service on port 22.

Commands entered in john's ordinary shell begin with $ and commands entered in a root shell begin with #; the prompt marker is not typed. Single elevated steps from john's shell are written $ sudo command, which asks for john's password the first time in a session (the password is not echoed). The server-side sshd work uses a root shell, opened on sshserver with $ sudo -i and left with exit; each such block says so before it appears. Except where a block or its introduction names another host, commands run on sshadmin as john. Editing files uses the terminal editor from Chapter 3; accounts and sudo policy come from Chapter 2 and Chapter 5.

Create the workspace first; key-generation examples below use ~/.ssh as their working directory, and every other artifact stays in the workspace:

$ mkdir -p ~/debian-handbook/ssh

The command prints nothing on success. Make ~/debian-handbook/ssh the working directory with cd ~/debian-handbook/ssh; relative paths in the chapter are written from inside it.

One key pair carries the whole chapter. Generate it now, with ~/.ssh as the working directory:

$ ssh-keygen -t ed25519 -a 64 -C "john@sshadmin" -f id_ed25519
Generating public/private ed25519 key pair.
Your identification has been saved in id_ed25519
Your public key has been saved in id_ed25519.pub
The key fingerprint is:
SHA256:qyMz9bqiKx9uB05niCGdzTH6kGsN8K/Kge030pr7zig john@sshadmin
The key's randomart image is:
+--[ED25519 256]--+
|                 |
|.   o            |
| + * o           |
|o O o            |
|.o O    S        |
|o.* * .  .       |
|.=o* . ..        |
|Eo*=X ...        |
|.B@@+*++         |
+----[SHA256]-----+

Without -f, ssh-keygen asks where to save the key and offers /home/john/.ssh/id_ed25519 as the default. It then asks for a passphrase twice; nothing is echoed while typing. A passphrase encrypts the private key on disk - Section 20.2.1 shows the difference it makes. The transcript above shows the result once the passphrase is set.

Start an agent and load the key, so the passphrase is asked for once per session rather than once per connection:

$ eval "$(ssh-agent)" && ssh-add ~/.ssh/id_ed25519
Identity added: /home/john/.ssh/id_ed25519 (john@sshadmin)

ssh-add asks for the key's passphrase before printing the confirmation line. The eval runs the agent in the background and exports SSH_AUTH_SOCK, the socket through which ssh programs reach it; Section 20.2.3 covers the mechanism.

Give the client its per-host configuration. This is the file the whole chapter connects through; its pieces are taken apart in Section 20.5.1:

# ~/.ssh/config (on sshadmin)
Host sshjump
    HostName 192.168.220.30
    User john
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes

Host sshserver
    HostName 192.168.221.20
    User john
    ProxyJump sshjump
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes

ProxyJump sshjump routes connections to sshserver through the jump host; Section 20.5.2 explains how it works and why it is the preferred form of relaying.

Two more pieces of starting state come from the practice network's provisioning, done over the trusted administration channel: john's public key is already in ~/.ssh/authorized_keys on sshjump and sshserver, and the two servers' ed25519 host-key records are already in ~/.ssh/known_hosts on sshadmin. Section 20.1.3 shows how those host keys are read and verified from the server side, and Section 20.2.2 shows the client-side procedure for installing a public key. The exercises rely on this starting state exactly as a production site relies on its provisioning records.

The inspection tools come from Chapter 17; the host firewall that admits or blocks port 22 is Chapter 18's. Time synchronization matters more here than almost anywhere else, because SSH certificate validity windows are clock-based - Chapter 10. For file sharing at network scale, see Chapter 21; for WireGuard as an alternative encrypted access path, Chapter 19.

In this section