What is SSH and what exactly happens when you connect
Published on 2026-09-12 by frfrand
What happens when you connect via SSH: the key pair, the challenge your machine signs, why the public key is not a risk, and what host changed means.

Short answer: SSH opens an encrypted channel with the server and, if you use keys, it authenticates you without your secret traveling: the server sends a random challenge, your machine signs it with the private key, and the server verifies the signature with the public key it already had. That's why the public key can be distributed without risk and the private key never leaves your computer.
SSH is the protocol you use to access a server. Everyone knows that. What usually remains blurry is what happens in the second between pressing Enter and the prompt appearing.
It's worth it, because that's where the answers to almost all the security questions that come up later come from.
The key pair, and which one is shared
When you generate a key, two files are created:
~/.ssh/id_ed25519 the private key ~/.ssh/id_ed25519.pub the public key
The private key lives on your computer and never leaves it. Never. It is not sent by email, not pasted in a chat, not uploaded to a repository.
The public key is distributed: it goes to each server where you want to log in, inside the ~/.ssh/authorized_keys file.
The most common confusion is thinking that delivering the public key is risky. It isn't, and not by convention but by mathematics: from the public key, the private key cannot be deduced. That's why a server can have the public keys of ten people without any problem.
Practical rule: if you ever copied the file without the .pub somewhere, generate a new pair today.
What happens when you connect
- Your client connects and both parties agree on an encryption for the session.
- The server sends a challenge: a random value, different every time.
- Your machine signs it with the private key and returns the signature.
- The server verifies that signature with the public key it already had. If it matches, you're in.
The important thing about this dance: your private key never travels, and the challenge changes on every connection, so capturing the traffic is useless for getting back in later.
With a password, on the other hand, the secret does travel (encrypted, but it travels) and the server receives it. A compromised server keeps your password. With keys, it keeps a signature that is useless for anything else.
That giant warning that scares you
The first time you log into a server, SSH saves its fingerprint in ~/.ssh/known_hosts. If that fingerprint changes, the REMOTE HOST IDENTIFICATION HAS CHANGED warning appears.
Almost always it's one of two things:
- They reinstalled the server or regenerated its keys. It happens often and is harmless.
- Someone got in the middle and is impersonating the server.
The usual reflex is to delete the line from known_hosts and continue. It's fine to do it after confirming the first case, not before. It's ten seconds of asking.
Three things worth their weight in gold
ssh-copy-id installs your public key on the server without editing files manually:
ssh-copy-id deploy@miservidor.com
The ~/.ssh/config file saves you from remembering user, port, and key:
Host prod HostName miservidor.com User deploy Port 2222 IdentityFile ~/.ssh/id_ed25519
From there, ssh prod. And the best part: scp, rsync, git, and editors read that same file.
Add a passphrase to the private key. If your laptop is stolen, the key alone is not enough. To avoid typing it every time, there is the agent: ssh-add keeps it for the duration of your session.
And the permission that breaks everything
chmod 700 ~/.ssh chmod 600 ~/.ssh/id_ed25519 chmod 600 ~/.ssh/authorized_keys
SSH refuses to use a private key that other users can read, and it does well. If one day your key "stops working" without you having touched anything, check the permissions: it is almost always that, after copying the folder from one place to another.


Practical example: an SSH connection to a VPS
When you connect from the terminal with ssh usuario@servidor, the client verifies the server's identity using its host key and negotiates an encrypted channel. The first time, check the key fingerprint through a trusted channel; accepting any warning without verifying it can open the door to impersonation.
On an ArduMaker VPS, Linux users are created from the panel with a password, and public keys are loaded from the SSH Access app for a single VPS user. Each VPS is born with its own host keys, generated when it is created, so the fingerprint you save corresponds only to that server. It is recommended that each key be for a single person, grant minimum permissions, and remove access when it is no longer necessary. For specific queries, the web terminal allows you to work from the panel according to the available permissions. Do not disable host checking to resolve connection errors.
Related: How to manage team access · Documentation.
Frequently asked questions
Is it dangerous to share my public key? No. The private key cannot be deduced from the public key; it is made to be placed on each server where you want to log in.
What do I do with the warning REMOTE HOST IDENTIFICATION HAS CHANGED? First confirm whether the server was reinstalled or its keys were changed. Only then delete the old line from known_hosts; if no one touched the server, do not connect.
Why does SSH ignore my private key? Almost always due to permissions: ~/.ssh must be set to 700 and the private key to 600.
What is the passphrase for? So that the key file, if your laptop is stolen, is not enough on its own. With ssh-add you don't have to type it on every connection.