Advanced · 30 minutes · Guided lesson

SSH connections and trust

Separate transport, host identity and user authentication failures.

By the end of this lesson

  • Distinguish a server host key from a user login key
  • Interpret connection and authentication errors separately
  • Choose a safe next check for a changed host key

Your environment: The live configuration example requires OpenSSH. The offline scenario does not require a second server. Setup help

There are two identities to verify

SSH encrypts a connection and authenticates parties, but several stages must work before a shell appears. First the client reaches an SSH server. The server presents a host key, which the client can compare with a previously trusted key. User authentication then proves that the connecting user is allowed to log in.

A host key identifies the server; a user key identifies a login credential. A public user key may be authorised on a server, while its private counterpart must remain private. Never upload a private key to a training site or paste it into a support ticket.

Read the failure before changing trust

Connection refused points towards a transport/listener or reject condition, not a wrong user password. Permission denied after an SSH connection usually concerns authentication or access policy. Check the username, offered identity and server policy rather than repeatedly changing unrelated network settings.

A changed host-key warning can follow a legitimate rebuild, but can also mean you reached the wrong host. Verify the expected fingerprint through an independent trusted channel before updating known_hosts. Disabling strict host-key checking turns off an important protection and is not the default repair. Verbose client output can help, but redact private operational details before sharing it.

See it in context

Worked example

Inspect the effective SSH client configuration without connecting.

ssh -G example.com | head -n 20

OpenSSH prints evaluated configuration and exits. This does not authenticate to the host. Host, user and identity settings can come from SSH configuration files.

Your turn

Practical lab

Triage three SSH symptoms using an offline evidence set.

Run commands in your own lab. This website displays instructions; the practice terminal below helps you rehearse the syntax.

1. Prepare your workspace

mkdir -p "$HOME/training4linux/ssh"
cd "$HOME/training4linux/ssh"
printf "%s\n" "A: connect to host lab.example port 22: Connection refused" "B: Permission denied (publickey)" "C: REMOTE HOST IDENTIFICATION HAS CHANGED" > symptoms.txt

2. Complete the task

  1. Assign each symptom to transport/listener, authentication or host identity.
  2. Choose a read-only next check for each symptom.
  3. Write the independent verification required before replacing a trusted server fingerprint.

3. Check your result

  • A concerns connection establishment; B concerns user authentication; C concerns server identity.
  • You have not proposed deleting all known_hosts entries or disabling host verification.
Need a hint?

Ask whether the connection reached the server, whether its identity is trusted, and whether your account is allowed.

Reveal a worked solution

Compare this with your approach after trying the task. More than one valid solution may exist.

cat symptoms.txt
printf "%s\n" "A: verify destination and inspect the authorised server listener." "B: verify username, selected public key and server authorisation." "C: verify the fingerprint with the server owner through a trusted channel." > next-checks.txt

After the lab: No connection or key changes are required for the scenario.

Common mistakes to avoid

  • Do not publish private keys in learner notes or screenshots.

Check your understanding

Knowledge check

Answer all 3 questions correctly to pass. Retry as often as you need; your best score is kept.

1. What does a host key identify?
2. What is the right first response to an unexpected changed host key?
3. Which key must remain private?

Your lesson progress

Not started · Best score: 0% · Attempts: 0

Practical completion is self-reported. Progress is linked to a private cookie in this browser and stored on the site. Clearing that cookie loses access to it. Manage or erase progress.

Keep the reference close

Further reading