Skip to content

First SSH connection

Module
Basic Connectivity and Remote Access
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS (two lab containers), GNU Bash 5.2.21
Prerequisites
On this page

Your first SSH connection pauses before asking for a password. It says the host’s authenticity cannot be established and shows a fingerprint. Typing yes without checking it would skip the part that identifies the server you are about to trust.

By the end, you can compare that fingerprint through a trusted console, authenticate to the intended account, run commands at the remote prompt, and return to your local shell.

Finish Retrieving content. Start locally in ~/lab, from the B04 setup. Use the prepared lab server.

The lab supplies learner@labserver, its password learner, and separate server-console access. The password is for this isolated teaching account only. To repeat this on your own, you need a second machine you control that runs an SSH server, with console access to it; the name labserver is not available there.

The recording uses a private Docker bridge between two containers, not a home network. Your addresses, host-key fingerprints, and login banner will differ. Each capture starts a server with fresh host keys. Its banner names the container’s shared kernel, including microsoft-standard-WSL2; your banner names your own system and kernel.

The lab server creates new host keys every time it starts. A saved labserver key from an earlier lesson would trigger OpenSSH’s REMOTE HOST IDENTIFICATION HAS CHANGED warning. Here you know why the key changed: the lab server was recreated. After checking its current fingerprint through the trusted server console, use ssh-keygen -R labserver locally if an earlier entry remains, then connect and compare the fingerprint. For an unexpected change, stop and verify the reason and fingerprint through the server console before removing the saved entry.

Read the server’s identity through its console

Section titled “Read the server’s identity through its console”

On the server console, learner@labserver:~$, run:

Terminal window
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
Server console: read the host key before connecting
learner@labserver:~$ ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub256 SHA256:S4p5g8NxO8wKRdWAHCB1Lqui4xGqKxXPhc7cYoxShOk root@labserver (ED25519)learner@labserver:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS (lab server console), GNU Bash 5.2.21. Trusted server console: read the complete ED25519 host-key fingerprint before starting the client connection.
Steps (3)
  1. Type ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
  2. Press Enter — Trusted server console: compare this complete SHA256 fingerprint with the client prompt
  3. Output: 256 SHA256:S4p5g8NxO8wKRdWAHCB1Lqui4xGqKxXPhc7cYoxShOk root@labserver (ED25519)

A host key identifies an SSH server. A fingerprint is a compact digest of its public key. ssh-keygen -l displays the fingerprint, and -f selects the public-key file. The .pub file is public information; you are not reading the private host key.

Keep the complete SHA256: value available for comparison. The comment at the end, root@labserver, is key metadata. It does not mean you will log in as root. Your requested account is learner.

This console is a separate trusted route to the server, available before the SSH login. On a VM, it could be the hypervisor’s console. Checking a fingerprint through the same unverified SSH connection would not independently establish the server’s identity.

Start the client and compare the whole fingerprint

Section titled “Start the client and compare the whole fingerprint”

Return to the local shell, learner@rootvolt:~/lab$. Start the client:

Terminal window
ssh learner@labserver

The local ssh program is the client. The SSH server on labserver listens for requests on TCP port 22. The argument selects the remote account before @ and the destination hostname after it.

On this first connection, the client has no saved key for the hostname. It displays an ED25519 fingerprint and asks whether to continue. Compare the entire SHA256 value with the console’s value, character for character, including its case. The punctuation ending the client’s sentence is not part of the fingerprint.

Predict: does knowing the account password establish that the host key belongs to the intended server?

Run it, then compare with your guess

No. Server identity and account authentication are separate checks. Verify the server’s fingerprint before sending the account password.

Local client: verify identity before authentication
learner@rootvolt:~/lab$ ssh learner@labserverThe authenticity of host 'labserver (172.19.0.2)' can't be established.
ED25519 key fingerprint is SHA256:S4p5g8NxO8wKRdWAHCB1Lqui4xGqKxXPhc7cYoxShOk.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yesWarning: Permanently added 'labserver' (ED25519) to the list of known hosts.
learner@labserver's password: Welcome to Ubuntu 24.04.5 LTS (GNU/Linux 6.18.33.1-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.learner@labserver:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. LOCAL learner@rootvolt compares the matching server fingerprint, answers yes, and authenticates without displaying the password.
Steps (9)
  1. Type ssh learner@labserver
  2. Press Enter — LOCAL learner@rootvolt: compare the shown fingerprint with the trusted server console
  3. Output: The authenticity of host 'labserver (172.19.0.2)' can't be established. ED25519 key fingerprint is SHA256:S4p5g8NxO8wKRdWAHCB1Lqui4xGqKxXPhc7cYoxShOk. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])?
  4. Type yes into the running program
  5. Press Enter — Accept only after the complete fingerprint matches
  6. Output: Warning: Permanently added 'labserver' (ED25519) to the list of known hosts. learner@labserver's password:
  7. Type the password (the terminal shows nothing)
  8. Press Enter — Authentication succeeds; the prompt changes to REMOTE learner@labserver
  9. Output: Welcome to Ubuntu 24.04.5 LTS (GNU/Linux 6.18.33.1-microsoft-standard-WSL2 x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/pro The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details.

The step notes annotate the sequence: compare first, accept second, authenticate third. Only after a match, type yes and press Enter. SSH records the accepted key in local ~/.ssh/known_hosts. If it does not match, answer no and investigate through the trusted console rather than accepting it.

After host verification, the client asks for learner’s password. Authentication establishes that you may use the requested account. Type the lab password and press Enter. Nothing appears while you type: no letters and no replacement stars. The replay also keeps it hidden.

Password authentication is the method configured for this lab. Other servers may require SSH keys or another method. The host key you checked is the server’s identity; it is not a user login key and not the account password.

The welcome banner appears after authentication here. Then the prompt changes to learner@labserver:~$. The username stayed the same, but the host and working directory changed. You have a remote shell, not a second local directory named labserver.

At the remote shell, run:

Terminal window
hostname; pwd
exit

The semicolon separates two commands, as in earlier shell work. hostname identifies the machine executing them; pwd identifies the directory on that machine. The capture prints labserver and /home/learner.

After exit, run this at the local shell:

Terminal window
hostname
Remote commands, exit, and local identity
learner@labserver:~$ hostname; pwdlabserver
/home/learnerlearner@labserver:~$ exitlogout
Connection to labserver closed.learner@rootvolt:~/lab$ hostnamerootvoltlearner@rootvolt:~/lab$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. REMOTE learner@labserver reports its home directory; exit closes that shell, and LOCAL learner@rootvolt confirms the return.
Steps (9)
  1. Type hostname; pwd
  2. Press Enter — REMOTE learner@labserver: identify the machine running the command
  3. Output: labserver /home/learner
  4. Type exit
  5. Press Enter — Leave the remote shell; return to LOCAL learner@rootvolt
  6. Output: logout Connection to labserver closed.
  7. Type hostname
  8. Press Enter — LOCAL learner@rootvolt: verify the return
  9. Output: rootvolt

Exit ends this remote shell and closes the connection. It does not shut down the server. Your local shell resumes in its original ~/lab directory. Read the host in the prompt before any file-changing command: the same absolute path can name different files on the two machines.

Treating the first-connection question as a password prompt. It asks whether to trust a host key. Compare the fingerprint before answering; the password prompt comes later.

Reading the same username as the same machine. Learner exists on both systems. The host part of the prompt, rootvolt or labserver, distinguishes their shells.

Removing a saved key to silence an unexpected warning. A changed key can mean a rebuilt server or an impersonation attempt. Verify the reason and current fingerprint independently. This lab deliberately creates fresh servers; that does not make unexpected key changes safe elsewhere.

Goal: You have authenticated, and pwd reports /home/learner. Explain how to determine which machine owns that directory, then return without shutting it down.

Solution

Read the host in the prompt and check hostname. At learner@labserver, the directory belongs to the server’s filesystem. Exit leaves the remote shell; the local prompt returns. A local hostname check then reports rootvolt in this lab.

The remote commands were read-only. Exit already ended the remote shell. At the local shell, reset trust in this lab server:

Terminal window
ssh-keygen -lf ~/.ssh/known_hosts
ls -a ~/.ssh
ssh-keygen -R labserver
ssh-keygen -F labserver || printf 'No saved key for labserver\n'
pwd
Reset local exercise files and trust in labserver
learner@rootvolt:~/lab$ ssh-keygen -lf ~/.ssh/known_hosts256 SHA256:S4p5g8NxO8wKRdWAHCB1Lqui4xGqKxXPhc7cYoxShOk |1|6trZE9uB8XeSV7Qc17VUWQDdHEU=|lIoA5E4TplXkJEJqJzEjRgQ9aa0= (ED25519)
3072 SHA256:CYuJDb5kP9ey72Ik/COuKGZcSeRc091Mjl/HV1jmUDM |1|lhoz2LrXgJTpHsmsxfr9auX5A98=|sjNBS1ASbjQb30uwIVFGGRoXcSg= (RSA)
256 SHA256:UCanoM643MLEHufyXuxgiSTPgtdZuXNFjNzq/Q4qMxI |1|AWs664ngKI7S6Si5PkaOCPB5PCw=|opNrbGUqpcOT8HGVo6BnPtOBwMM= (ECDSA)learner@rootvolt:~/lab$ ls -a ~/.ssh.  ..  known_hosts  known_hosts.oldlearner@rootvolt:~/lab$ ssh-keygen -R labserver# Host labserver found: line 1
# Host labserver found: line 2
# Host labserver found: line 3
/home/learner/.ssh/known_hosts updated.
Original contents retained as /home/learner/.ssh/known_hosts.oldlearner@rootvolt:~/lab$ ssh-keygen -F labserver || printf 'No saved key for labserver\n'No saved key for labserverlearner@rootvolt:~/lab$ pwd/home/learner/lablearner@rootvolt:~/lab$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. LOCAL reset removes only labserver's saved host keys, confirms none remain, and retains the original working directory.
Steps (15)
  1. Type ssh-keygen -lf ~/.ssh/known_hosts
  2. Press Enter — List the saved host key fingerprints and their key types
  3. Output: 256 SHA256:S4p5g8NxO8wKRdWAHCB1Lqui4xGqKxXPhc7cYoxShOk |1|6trZE9uB8XeSV7Qc17VUWQDdHEU=|lIoA5E4TplXkJEJqJzEjRgQ9aa0= (ED25519) 3072 SHA256:CYuJDb5kP9ey72Ik/COuKGZcSeRc091Mjl/HV1jmUDM |1|lhoz2LrXgJTpHsmsxfr9auX5A98=|sjNBS1ASbjQb30uwIVFGGRoXcSg= (RSA) 256 SHA256:UCanoM643MLEHufyXuxgiSTPgtdZuXNFjNzq/Q4qMxI |1|AWs664ngKI7S6Si5PkaOCPB5PCw=|opNrbGUqpcOT8HGVo6BnPtOBwMM= (ECDSA)
  4. Type ls -a ~/.ssh
  5. Press Enter — Inspect the SSH directory before removing the labserver entry
  6. Output: . .. known_hosts known_hosts.old
  7. Type ssh-keygen -R labserver
  8. Press Enter — Remove only saved host keys for labserver
  9. Output: # Host labserver found: line 1 # Host labserver found: line 2 # Host labserver found: line 3 /home/learner/.ssh/known_hosts updated. Original contents retained as /home/learner/.ssh/known_hosts.old
  10. Type ssh-keygen -F labserver || printf 'No saved key for labserver\n'
  11. Press Enter — Confirm no saved key for labserver remains
  12. Output: No saved key for labserver
  13. Type pwd
  14. Press Enter
  15. Output: /home/learner/lab

The fingerprint listing shows three saved key types for this server: ED25519, RSA, and ECDSA. After login, OpenSSH’s host-key update saves the server’s other key types too. These are three keys for one host, which explains the reset’s three found lines. The |1|... field is the host name stored in hashed form, as Ubuntu’s client saves it, so known_hosts does not list the hosts you visit in plain text; the hashes and the order of the three lines differ in your listing. The directory listing shows known_hosts.old already exists before the reset: the host-key update also made a backup.

ssh-keygen -R labserver removes only that host’s entries. In this capture, it reports Host labserver found for lines 1, 2, and 3, then names the updated /home/learner/.ssh/known_hosts file and the retained /home/learner/.ssh/known_hosts.old backup. ssh-keygen -F looks for a saved key; the fallback prints No saved key for labserver when none remains. The known_hosts file (empty in this recording) and known_hosts.old backup are harmless and are not deleted. Your ~/.ssh directory and other hosts’ entries stay.

The lookup confirms that no saved labserver key remains. Pwd still reports /home/learner/lab.

  • Verify the server’s host key through a trusted independent source before accepting it.
  • Authenticate to the requested account after checking server identity.
  • Use the host in the prompt to distinguish local and remote commands.
  • Exit ends the remote shell and returns to the local one.
  • Reset labserver trust with ssh-keygen -R labserver; retain other hosts and the backup.

Next, Transferring files with SFTP moves a practice file between the two filesystems.