Linux Intermediate 08 — SSH Keys, Host Identity, and File Transfer

Linux course index · Linux Intermediate category · Lesson 8 of 9

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Verify an SSH host’s identity, use a passphrase-protected key, and transfer a non-sensitive file.

Concepts and setup

SSH transport establishes encrypted communication. The server host key proves the server identity when pinned or verified. Your user key proves that you own a private key allowed for the remote account. Those keys solve different problems. Use a dedicated lab key and keep the private key on the client. Never suppress host-key checking to make a warning disappear.

Use two VMs you control on an isolated network. Replace labuser and 192.168.56.20 with your own account and server. Use the VM console to verify the fingerprint on first connection.

Record a host fingerprint and connect

# Server console, if it uses this Ed25519 host key:
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
# Client:
install -d -m 700 ~/.ssh
ssh-keygen -t ed25519 -f ~/.ssh/oe-linux-lab -C oe-linux-lab
ssh-copy-id -i ~/.ssh/oe-linux-lab.pub labuser@192.168.56.20
ssh -i ~/.ssh/oe-linux-lab -o IdentitiesOnly=yes labuser@192.168.56.20 'id -un; hostname'

Possible output

256 SHA256:EXAMPLE-FINGERPRINT labhost (ED25519)
...
labuser
labhost

Use an unused key filename and give the key a passphrase. ssh-copy-id assumes an authorized way to sign in the first time. Verify the client prompt against the console’s actual fingerprint before accepting.

Transfer a fixture and confirm content

lab=$(mktemp -d)
printf 'Linux SSH lab\n' > "$lab/message.txt"
scp -i ~/.ssh/oe-linux-lab -o IdentitiesOnly=yes "$lab/message.txt" labuser@192.168.56.20:oe-lab-message.txt
ssh -i ~/.ssh/oe-linux-lab -o IdentitiesOnly=yes labuser@192.168.56.20 'cat ~/oe-lab-message.txt'

Possible output

message.txt                   100%   14 ...
Linux SSH lab

Use a fresh remote filename. Remove the fixture and the specific lab public key from authorized_keys when retiring the lab. Leave any other keys alone.

Questions only

Quick-check questions

  1. Why should only the public user key be installed on the server?
  2. What should you do if a previously known host key changes unexpectedly?

Assessment questions

  1. Distinguish Permission denied from Connection refused in this lab.
  2. State where to verify the new host key before trusting it.
  3. How would you confirm that you are using the intended client identity rather than another configured key?

Questions and answers

Quick-check answers

  1. Why should only the public user key be installed on the server?
    Answer — The private key enables authentication and should remain under the client’s control.
  2. What should you do if a previously known host key changes unexpectedly?
    Answer — Stop. Verify through a trusted separate channel, such as the VM console, before updating the saved host entry.

Assessment answer key

  1. Distinguish Permission denied from Connection refused in this lab.
    Answer — Permission denied usually follows a successful transport and failed authorization or authentication. Connection refused usually points earlier to the listening endpoint or an active rejection.
  2. State where to verify the new host key before trusting it.
    Answer — Record the fingerprint at the VM console or another approved trusted source. Compare it to what the client reports.
  3. How would you confirm that you are using the intended client identity rather than another configured key?
    Answer — Use -i with the intended key and -o IdentitiesOnly=yes. Inspect a verbose client trace if necessary, without publishing identifying details.

Source articles on this site

Continue the course

Previous lesson 07 — IP Addresses, Routes, and Name Resolution. Next lesson 09 — Block Devices, Filesystems, and Mounts.

Linux course index · Linux Intermediate category · Lesson 8 of 9

Leave a Reply