20.1. Installing and Operating OpenSSH
Debian splits OpenSSH into a client package and a server package. The client is present on most systems because so much depends on it; the server is a deliberate installation decision, and everything in this chapter that configures a host to accept connections starts there.
20.1.1. Client and Server Packages and Service Activation
The two packages divide the software cleanly:
| Package | Contents | When it is needed |
|---|---|---|
openssh-client |
ssh, scp, sftp, ssh-keygen, ssh-agent, ssh-add, ssh-copy-id |
On any host used to reach other systems; installed by default on most desktop and server installs |
openssh-server |
sshd, its configuration under /etc/ssh, and the host-key generation that runs when the package is first installed |
On hosts that must accept SSH connections |
Check what the lab's Debian 13 hosts run, on sshadmin as john:
$ dpkg-query -W -f='${Package} ${Version}\n' openssh-client openssh-server
openssh-client 1:10.0p1-7+deb13u4
openssh-server 1:10.0p1-7+deb13u4
All three hosts carry both packages; the version identifies the exact software every exercise ran against. Ask the client for its protocol banner:
$ ssh -V
OpenSSH_10.0p2 Debian-7+deb13u4, OpenSSL 3.5.6 7 Apr 2026
On a host that lacks the server package, sudo apt install openssh-server
installs it, generates a fresh set of host keys under /etc/ssh, and
enables the service - Chapter 6 covers the
package mechanics. On the lab's sshserver it is already present, so
verify the service state instead, on sshserver as john:
$ systemctl is-enabled ssh
enabled
$ systemctl is-active ssh
active
is-enabled reports what will happen at boot; is-active reports what
is true now. A server that shows disabled but active is running until
the next reboot and should be enabled with sudo systemctl enable ssh.
The service listens on all addresses on port 22 by default; if a host
firewall is in play, its rules must admit that port
(Chapter 18). Service operations such as reload
are Chapter 8's subject and are used below exactly
as described there.
20.1.2. Server Configuration Includes and Effective Settings
sshd reads one main file, /etc/ssh/sshd_config, and Debian ships that
file with an Include directive near the top. On sshserver as john:
$ grep -n "^Include" /etc/ssh/sshd_config
12:Include /etc/ssh/sshd_config.d/*.conf
Everything after line 12 that looks like a flat file is really a
two-level structure: the main file plus every *.conf file in
/etc/ssh/sshd_config.d/, read where the Include line appears. That
placement is the whole trick. sshd configuration uses first value wins:
for each keyword, the first setting encountered is used and later ones
are ignored. Because the Include sits at the top, a drop-in file
overrides anything written later in the main file, and a package or an
administrator can adjust one setting without editing the main file at all.
Reading a server therefore means reading the effective result, not
guessing from a list of files. sshd -T prints it, as root:
$ sudo sshd -T | grep -E "^(port|permitrootlogin|passwordauthentication|pubkeyauthentication|authorizedkeysfile)"
port 22
permitrootlogin without-password
pubkeyauthentication yes
passwordauthentication no
authorizedkeysfile .ssh/authorized_keys .ssh/authorized_keys2
Each line is the setting sshd will actually enforce. This server accepts
public-key authentication, refuses password authentication, allows root
to log in only with a key (without-password), and looks for user keys in
~/.ssh/authorized_keys. Do not assume those values on another host:
read them the same way. sshd -T prints the whole configuration - the
grep shown selects five well-known lines from it.
Watch the include mechanism work. On sshserver, open a root shell
(sudo -i from john's shell; leave it with exit whenever the
server-side work pauses). The experiment uses a small configuration
file of its own, with a drop-in directory of its own, so the running
service is never touched:
# /etc/ssh/sshd_config.ch20include (on sshserver)
Include /etc/ssh/sshd_config.ch20.d/*.conf
Port 2222
HostKey /etc/ssh/ssh_host_ed25519_key
PidFile /run/sshd-ch20include.pid
PermitRootLogin no
AllowUsers john
Subsystem sftp internal-sftp
The file says PermitRootLogin no after the Include. Make the
drop-in directory and a drop-in file that says the opposite:
# install -d -m 755 /etc/ssh/sshd_config.ch20.d
The command prints nothing on success. Write the drop-in - redirection sends the text to the file, so nothing appears on the terminal:
# printf "PermitRootLogin yes\n" >/etc/ssh/sshd_config.ch20.d/10-test.conf
Then ask sshd for the effective result against this configuration:
# /usr/sbin/sshd -T -f /etc/ssh/sshd_config.ch20include | grep "^permitrootlogin"
permitrootlogin yes
The drop-in won, even though the main file's line comes later - because the drop-in was included first, and first value wins. Change only the drop-in:
# printf "PermitRootLogin no\n" >/etc/ssh/sshd_config.ch20.d/10-test.conf
It is again silent, and the effective value follows:
# /usr/sbin/sshd -T -f /etc/ssh/sshd_config.ch20include | grep "^permitrootlogin"
permitrootlogin no
This is the pattern to use for real changes too: put local policy in a
drop-in under /etc/ssh/sshd_config.d/ with a descriptive name, and
leave the main file as the package shipped it. Two cautions carry over.
First, sshd -T output can be context-dependent: settings inside a
Match block apply only to connections that match its criteria, and the
full output shows the no-match view. Second, the effective view is only
half the discipline - before any reload, validate the configuration with
sshd -t, which Section 20.4.2 exercises against a deliberately broken
file.
20.1.3. Host Keys, Fingerprints, and First-Connection Verification
When openssh-server was installed, it generated a fresh set of host
keys in /etc/ssh: one RSA, one ECDSA, and one Ed25519. These identify
the server, independently of any user. A client that connects for the
first time has a problem no protocol can solve by itself: the key it
receives could belong to the real server or to something pretending to be
it. OpenSSH's answer is to record the key on first contact and refuse to
continue if it ever changes - and to give the administrator a way to
compare, before accepting, what the server presents with what the
server is known to own.
The comparison uses fingerprints. On sshserver, in the root shell established in Section 20.1.2, read the Ed25519 host key's fingerprint:
# ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
256 SHA256:9qdmXSTataYe796D3K/2m36lAF5aFyA7lmQkn0FnD2M root@trixie (ED25519)
ssh-keygen -l prints the key size, the SHA256 fingerprint of the
public key, and the key's comment. The same procedure on sshjump yields
SHA256:/IP2vViiXsstIn0NDAslBfFkhY0VUUVRdg3v5pCax+o. A fingerprint like
this is what an administrator carries out of band - from a console session,
a provisioning record, or another already-trusted channel - and compares
against what the client reports at first connection. This is the
mechanism Section 2.5 of Chapter 2 refers to when
it establishes remote administration at first boot, and the one
Chapter 16 relies on when a recovery environment must
be trusted.
ssh-keygen mode |
Description |
|---|---|
-l -f file |
Print a key's size, fingerprint, and comment. |
-F host -f known_hosts |
Find the record for host in a known-hosts file. |
-R host -f known_hosts |
Remove the record for host from a known-hosts file. |
At first connection to a host not yet in ~/.ssh/known_hosts, ssh prints
the key type and fingerprint and asks whether to continue. Compare the
displayed fingerprint with the one obtained from the trusted source,
and answer yes only on a match. The [fingerprint] choice in the
prompt is the same comparison made mechanical: the answer itself may be
the fingerprint string, and ssh accepts it only if what was typed equals
what the server actually presented - an impostor cannot match the
fingerprint you obtained out of band. Either way ssh records the key,
and every later connection verifies the server against that record
silently. Answer no, or fail to verify, and the connection is refused.
If strict checking is enabled, an unknown host is refused outright with
no prompt. To see that refusal safely, run ssh from sshadmin against a
scratch known-hosts file that holds sshjump's record but not
sshserver's:
# ~/debian-handbook/ssh/known_hosts.empty (on sshadmin)
192.168.220.30 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFDj61pe37pck4oCCdxzhvQpI5SRdHMxXUmRF9OKRZMl root@trixie
$ ssh -o UserKnownHostsFile=~/debian-handbook/ssh/known_hosts.empty -o StrictHostKeyChecking=yes sshserver true
No ED25519 host key is known for 192.168.221.20 and you have requested strict checking.
Host key verification failed.
The jump leg authenticated cleanly - its record was present - and the destination was rejected because its key was unknown. Dropping the strictness override shows the prompt that the policy replaces - the same scratch file, the same destination, ssh's default behavior of asking:
$ ssh -o UserKnownHostsFile=~/debian-handbook/ssh/known_hosts.empty sshserver hostname
The authenticity of host '192.168.221.20 (<no hostip for proxy command>)' can't be established.
ED25519 key fingerprint is SHA256:9qdmXSTataYe796D3K/2m36lAF5aFyA7lmQkn0FnD2M.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? SHA256:9qdmXSTataYe796D3K/2m36lAF5aFyA7lmQkn0FnD2M
Warning: Permanently added '192.168.221.20' (ED25519) to the list of known hosts.
sshserver
The answer typed at the prompt was the fingerprint read on the server
earlier in this section, ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub.
It matched what sshserver presented, so the key was recorded - the
Warning: Permanently added line - and the command ran. Had the server
presented any other key, the typed string would not have matched and ssh
would have asked again (Please type 'yes', 'no' or the fingerprint:);
a plain yes accepts the displayed fingerprint without that
cross-check. The (<no hostip for proxy command>) in the prompt's host
line is the ProxyJump route showing through: ssh reached the
destination through the jump's pipe, so it has no destination address
of its own to display there. The scratch file now
holds sshserver's record for that address, written in the hashed form
the HashKnownHosts note below describes.
Many sites set StrictHostKeyChecking yes (or accept-new, which
accepts and records first keys automatically but still refuses any
later change) precisely because it turns a human decision into a
policy. What must never be done is disabling the check or discarding
known-hosts records to make a warning go away; a changed key is
information, not an obstacle (Section 20.6.3 shows the full warning
and what to do about it).
What the client trusts, it records. The practice hosts' keys were seeded
into john's known_hosts during provisioning, exactly as answering yes
at the prompt would have:
$ ssh-keygen -F 192.168.220.30 -f ~/.ssh/known_hosts
# Host 192.168.220.30 found: line 2
192.168.220.30 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFDj61pe37pck4oCCdxzhvQpI5SRdHMxXUmRF9OKRZMl root@trixie
$ ssh-keygen -F 192.168.221.20 -f ~/.ssh/known_hosts
# Host 192.168.221.20 found: line 4
192.168.221.20 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOPGaRkc4eDwxSjbhkH5HfUlxgQ0G4SAur/TuoT3cnE8 root@trixie
Each record ties a host address to one key. The file's first and third
lines hold the same two keys under the short names sshjump and
sshserver - the line numbers above show where - and its last lines
record the server's key under the bracketed forms
[192.168.221.20]:2222 and [192.168.221.20]:2226, which is how a
non-default port is looked up. The name-based host check that
Section 20.6.1 uses (HostKeyAlias) matches against the short-name
records. Depending on the client's HashKnownHosts setting the
stored names may be hashed for privacy; the lookup works the same way.
With trust and credentials both in place, the first real logins work -
over the work network to the jump host, and through it to the server:
$ ssh sshjump hostname
sshjump
$ ssh sshserver hostname
sshserver
Each command ran hostname on the far side and closed the session when
it finished. Running ssh sshserver with no command opens an
interactive shell on the server instead: ssh authenticates, runs the
login shell, and the terminal becomes a remote session. Leave it with
exit, or - when the session is wedged and will not take input - with
the escape sequence ~. typed at the start of a line. Which account you
get is sshd's decision, and restricting it is the next sections' work.