CentOS Distro - I created a custom private/public key pair in the home directory using ssh-keygen -f .custom_location/custom_key. Then I tried copying the public key to a test VM using only the remote VM's IP which has only two regular users (user1 and user2). How does ssh pick one user over another when prompting me for password for copying the public key? I confirmed that .ssh folder was created in only the user1. If I had three users, would it still prompt user1's password when copying the public key?

When I try to ssh into test VM using ssh -i .custom_location/custom_key username@ipaddress, why does it require private key? I thought public key is presented when connecting. Where is public key being used in the process?

I am confused as to who is the client and who is the server. Is the computer attempting the connection the client? and thus will have the known_hosts file?


1 Answer 1


I don't understand your first question but I can answer your second one.

You have to have private key on a source host when using a SSH client and using public key authentication because the public key authentication is based on asymmetric encryption. The private key is never sent over wire.

To understand more, you can on source host: ssh -v and on remote host configure /etc/ssh/sshd_config with LogLevel DEBUG3 and see the logs.

  • Does the remote server sends the encrypted public key which decrypted by private key from the client and the decrypted public key is sent to the remote server for verification?
    – Cruise5
    Dec 15, 2021 at 7:18
  • The private key never leaves your system, it is never sent over wire. If it would, it would make no sense to call it private key :D
    – Jiri B
    Dec 15, 2021 at 7:26
  • I said is the decrypted public key sent back to the server? Not private key.
    – Cruise5
    Dec 15, 2021 at 7:29
  • Public key is, well, public. It is meant to be transferred publicly. See: en.wikipedia.org/wiki/Public-key_cryptography Dec 15, 2021 at 9:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .