I'm trying to configure passwordless ssh. I've read the basic tutorials on the web but something is bothering me about the basic process.

Let's say I'm sitting at a client and want to log into a server (which happens to be on the local network, but that's not important). Anyway, it makes sense to me that I'd want to generate the key pair on the server and copy the public key onto the client. There are two reasons why it makes sense to generate the key pair on server:

  • You're already logged into the server account to which you want passwordless ssh, so that login info can be included in the key pair
  • You obviously want only the server's public key on the client

When ssh-ing into the server, the client sends the public key created on the server. The public key matches the private key on the server and the login is permitted.

But every tutorial I read has the key pair being created on the client and causing my brain to explode. I hope reading this doesn't cause your brain to explode. What am I missing?

1 Answer 1


I think taking a step back and looking at how asymmetric cryptography works would help. Every entity (client/server) starts with a key pair - one public key and one private key, which are mathematically linked.

In the standard process, we copy the client's public key over to the server. When the client connects, the server needs to validate that the client actually owns this key pair (remember that the public key is meant to be public, i.e. shared to other parties). So, it takes the public key, encrypts a random message with it (*), and sends it to the client. The client gets the encrypted message, decrypts it with its private key, and asks the server - 'Hey, is this the message?'. If the server agrees, the client is considered authenticated and the connection proceeds.

Let's reverse the scenario and see what happens. The server has a key pair, and the public key is with the client. The private key is required to prove identity, and that is only available to the server. So, a client can verify the identity of the server, but the reverse is not possible. Anyone who gets their hands on the server's public key (which is, again, meant to be public), can connect to the server. This is obviously a security problem.

By having each client use their own key pair with the private key on the client side, the server can verify the identity of each individual client. Only the clients who have their public keys added to the server's list of authorized keys can connect. The private keys on the client side are usually protected with an additional layer of encryption and a passphrase.

  • Thank you. Now I get it! I couldn't really think with my previous understanding. For instance, there was still the problem of authenticating the identity of the client. Apr 23, 2022 at 6:41
  • Is it the case that, once the client is authenticated, the presence of the client in the server's list of authorized keys serves as the necessary login credential? Or is the server supposed to at least initially ask the client for the server password? Apr 23, 2022 at 6:50
  • @TomRussell The client is allowed to connect if its public keys is present in the authorized keys file for the specific user account. If password-based access is available, ssh-copy-id can copy the key for you. Otherwise, the procedure is to share the public key to the system administrator, who will then add it manually to the file.
    – Haxiel
    Apr 23, 2022 at 8:45
  • @TomRussell To help with troubleshooting, try connecting with ssh -vvv user@host. It prints out a lot of extra information, including the authentication methods attempted and why they are failing. The server-side SSH daemon enforces the rules, and it could be possible that public-key auth is simply not enabled. You'll need to reach out to your SysAdmin in such cases.
    – Haxiel
    Apr 23, 2022 at 8:47
  • 1
    Don’t forget the client’s pubkey has to be in the remote user’s ~remoteuser/.ssh/authorized_keys file, and that file should be readable only by the user, and so should the .ssh directory. I like to set the file to 0600 and the directory to 0700.
    – jsbillings
    Apr 23, 2022 at 15:33

You must log in to answer this question.

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