I am trying to setup SSH key based login from server A to server B.

I ran ssh-keygen on server A and used ssh-copy-id to copy the id_rsa.pub to server B. When I try to ssh user@serverB from server A, I keep getting the error:

Permission denied (publickey).

I have double checked my /etc/ssh/sshd_config file to make sure everything is setup correctly. Also have SELinux disabled on both servers. Any idea what could be causing this problem.

  • Check the permissions on the folder and key; check that the key is of a type that the server can accept (does it have to be an ecdsa key?); run the ssh command with -vvv and see what it says. Oct 24, 2022 at 5:57
  • Try debugging the authentication by looking at /var/log/auth.log. If not present, you need to enable SyslogFacility AUTH in sshd_config, and maybe adjust (r)syslogd config accordingly.
    – gerhard d.
    Oct 24, 2022 at 6:32
  • /var/log/auth.log is part of Debian-style (r)syslog configuration; RedHat-related distributions might use /var/log/secure for the same purpose. And the logs should be checked specifically on server B.
    – telcoM
    Oct 24, 2022 at 6:34

2 Answers 2


It turned out that the RSA key on the new server that I was logging in from (server A) was of a bigger size than what the old server I was logging in to (server B) could handle. I generated a ed25519 key on the new server and adding that to the authorized_keys file worked. Good reason to start moving away from RSA keys.


You need to check:

  • The types of key the server B can accept
  • If the ssh pubkey is applied correctly to the authorized_keys file of the user you're trying to login with the key (usually ~/.ssh/authorized_keys)
  • The permission of the private key (Needs not to be open to other users)
  • The permission of the authorized_keys file (Same as above).
  • The owner of the authorized_keys file (Needs to be the user).

The output would be more helpful, but for now, that's all I can think of.

  • Also ownership and permissions of the all the directories containing the keys, including $HOME, /, $HOME/.. and $HOME/.ssh on server B. Some systems give each user their own group and make $HOME group writable which can cause issues.
    – icarus
    Oct 24, 2022 at 15:01

You must log in to answer this question.

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