Does the "authenticity of host can't be established" message in SSH reflect a security risk?

Whenever I connect to a new SSH server from my computer I get this message:

The authenticity of host '[censored]:censored ([0.0.0.0]:censored)' can't be established.
RSA key fingerprint is SHA256:censored.
Are you sure you want to continue connecting (yes/no)?

Why does SSH ask me that?

Do I have any risk of connecting to a random SSH server?

Or is this just to make sure the server you are connecting to hasn't been hacked?


Solution 1:

It's asking you because it's never connected to this host before.

If you are in a secure environment, then you will know the remote host's fingerprint, and will compare it on the first connection - if the fingerprint matches what you know it should be, then great. If you're in a less secure environment, then you can just accept it on first connection.

Once you've said "Yes, I trust that host key, and want it to be associated with that hostname/IP", the SSH client will remember this for you... If for whatever reason (reinstall / new host keys / new machine / man in the middle) the key doesn't match on a subsequent connection, you will see a warning like below:

$ ssh baloo
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:Su0uy/4BcRcpmyLfxO9ndlcda52F8uct6yWNp7Sa92M.
Please contact your system administrator.
Add correct host key in /home/attie/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/attie/.ssh/known_hosts:65
  remove with:
  ssh-keygen -f "/home/attie/.ssh/known_hosts" -R baloo
ECDSA host key for baloo has changed and you have requested strict checking.
Host key verification failed.

In this situation, if you know that the remote host has indeed been changed, then you can proceed... possibly verifying that the fingerprint is correct.

If you are unsure, or know that the remote host should not have changed, then it will clue you in to a potential attack.

Solution 2:

When you get this message SSH is simply saying "I have never seen this computer before so I can’t be sure it’s who it says it is. Do you trust it?" At which point you can say that you trust it and in the future your computer will remember and not ask you again.

Ideally to trust it you should manually compare the key provided with the key on the server (as you would trust a GPG key by checking that the person who you believe it belongs to can actually generate the public key). Although in reality people don’t bother with this (at least from my knowledge).

The real benefit comes from each subsequent time you connect to the server. If SSH complains about the server which you have already trusted not being the same server then there is a chance you are the victim of a MiTM attack.

Over all if you are on a network where you are confident there is no Man in The Middle attack going on and this is the first time you are connecting to the computer then you should be safe to accept the key. (although if you are working on some top secret government mission then maybe ask your system administrator to verify the fingerprint before connecting)