Ok, I was pushed to write up some answer to clear things up. Not that the other would be completely wrong, but it does not show the whole picture of what is going on in the SSH protocol.
The authentication to ssh
server works in two steps. The first one is validation if your public key is in the authorized_keys
file, the second one checks if the signature provided by the appropriate private part is valid. In the server debug log, you can see:
sshd[9951]: debug1: test whether pkalg/pkblob are acceptable
sshd[9950]: debug1: matching key found: file /home/user/authorized_keys, line 1
sshd[9950]: Found matching RSA key: 8b:3c:20:c5:03:c4:c0:03:74:83:0a:8f:2d:d8:48:a2
sshd[9951]: Postponed publickey for vagrant from 10.0.2.2 port 54361 ssh2
referring to the first step (test whether pkalg/pkblob are acceptable
). And later one
sshd[9950]: debug1: matching key found: file /home/user/authorized_keys, line 1
sshd[9950]: Found matching RSA key: 8b:3c:20:c5:03:c4:c0:03:74:83:0a:8f:2d:d8:48:a2
sshd[9950]: Accepted publickey for user from 10.0.2.2 port 54361 ssh2
sshd[9950]: debug3: mm_answer_keyverify: key 0x7f54ce6ac570 signature verified
is checking the real signature made by the private part of the key.
Slightly paraphrased my answer from different question on sec.SE
But note, that the first step is not compulsory. If you specify only private key, or force the usage of specific key, the first step is skipped and in this case, the above question is correct.
All the above communication (authentication) is already encrypted. It goes on the wire, but it is not possible to intercept it in between. The server has to see it, if you offer this key.
If you are worried about your public key, note that for example Gitbub is exposing the public keys on the url https://github.com/<username>.keys
. It is not a big deal as a name (public) says. Based on this, there is service, which identifies you even outside of github, but you still need to do the first step (connect to untrusted server, which is usually bad idea).
ssh-keygen
(not the only way) by default the comment is user@host doing the creation. You can change the comment to something else or delete it, and if you use something other thanssh-keygen
there usually is no comment. If there is a comment, it's not sent to the server. The userid you are logging-on to on the server is sent, always (even if not using publickey).