Junior — Middle
How is server authentication verified during connection setup via SSH?
sobes.tech AI
Answer from AI
Server authentication during SSH connection is performed through a mechanism that verifies its public key.
When a client connects to a server, the server sends its public key. The client compares this key with the keys stored in the ~/.ssh/known_hosts file. If the key matches, the connection continues. If the key is new or has changed, the client warns the user about a possible "man-in-the-middle" attack.
Thus, trust in the server is established through verifying its public key, which prevents impersonation by an attacker.
Example of key verification:
ssh user@server
# On the first connection, a prompt will ask for key confirmation:
# The authenticity of host 'server (IP)' can't be established.
# Are you sure you want to continue connecting (yes/no)?
If the user types "yes", the key is saved in known_hosts for future checks.