$ ssh-keygen -t ed25519$ ssh-copy-id ana@web1$ ssh ana@web1ana@web1:~$ hostnameweb1privatepublicknown_hoststhe networknetworkencrypted channelsshd :22host keyauthorized_keysshellhostnameweb1
Back: your laptop (terminal, private key, public key, known_hosts). Middle: the network. Front: the server web1Yellow strip: the encrypted channel, there from the key exchange onTokens: the public key, a hello, the two one-time halves, the host key, a signature, a command and its answerYour laptop at the back: the terminal and three key files. The network in the middle, where an encrypted channel appears after the key exchange. The server web1 in front: sshd on port 22, its host key, authorized_keys and ana's shell. The public key is copied to the server; at login the client proves it holds the private key by sending a signature, and the private key never moves. Then commands and their answers travel through the encrypted channel. The terminal card shows only the commands. In real life ssh-keygen also asks where to save the key and for a passphrase, ssh-copy-id prints what it added, and the first ssh asks the fingerprint question shown in step 6.

Keys

  1. SSH, the Secure Shell, lets you type commands on a computer far away. Your laptop runs the ssh client. The server, web1, runs sshd, a program that waits for connections on port 22. Everything between them gets encrypted.

Connecting

Logging in

What happens

;; step 1/10 · remote
SSH      Secure Shell: log in to and run commands
         on a remote machine, over the network
client   ssh   on your laptop
server   sshd  on web1, listening on TCP port 22
network  anyone on the way may see the traffic,
         so SSH encrypts all of it

The terminal card shows only the commands. In real life ssh-keygen also asks where to save the key and for a passphrase, ssh-copy-id prints what it added, and the first ssh asks the fingerprint question shown in step 6. The key exchange shown is curve25519-sha256 (RFC 8731). Since OpenSSH 10.0 the default is mlkem768x25519-sha256, which mixes in a post-quantum method, but the idea is the same: a shared secret that never crosses the network. Never copy or share the private key file. If it leaks, remove the matching line from authorized_keys on every server and make a new pair. A passphrase protects the file if someone copies it.