You create a key pair and add the public key to the server. Then you connect, and the server asks for your password again. There is no error message. The key is correct, and the file is in the right place.
Often the cause is file permissions. By default, the SSH server checks who can change your home folder, the .ssh folder and the authorized_keys file. If the group or other users can write to any of them, another person could add their own key there. So the server does not trust the file and ignores it. The client is not told why. It simply gets the password prompt.
Remove write access for everyone except the owner. Then test again from your own computer:
# On the server, as the user who signs in
chmod go-w ~
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
# On your own computer: verbose output shows what happens to the key
ssh -v user@server
In the verbose output, look for the line Server accepts key. If you see it, the server now uses your key.
The full guide starts from the beginning. It creates an Ed25519 key with a passphrase and copies the public key with ssh-copy-id, with another way for Windows clients. It shows how ssh-agent keeps the key unlocked, so you do not type the passphrase for every connection. It turns off password sign-in in a safe order, with a configuration test before the reload. It also covers SELinux on RHEL and the mistake of copying the private key to a server.
Read the full guide: https://learnitlessons.com/articles/ssh-key-based-authentication/
Written with AI assistance and checked by the author.
Top comments (0)