Permission denied (publickey)

Hello, I generated a public key and added it to my ssh but I get a “Permission denied (publickey)” error when ever I try to log into the server using ssh. Does anyone know how to solve this issue?

Hello there,
I’m a CLIMB user, not an admin. To troubleshoot the “Permission denied (publickey)” error (trying to access a Linux virtual machine using SSH, but the authentication process fails due to issues with the public key), here are some common reasons for this error:

  1. No public key on the server: Ensure that your public key is added to the ~/.ssh/authorized_keys file on the virtual machine. If it’s not there, add it manually or use the ssh-copy-id command to copy your public key to the server. You mentioned you generated one, but after generation it must be added to the VM (either via Bryn, before its generation, or by an active user after it was generated)

  2. Incorrect permissions: The ~/.ssh directory and its contents must have the proper permissions. On the virtual machine, set the permissions as follows:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

(if you added the key via Bryn, the permission will be fine)

  1. Incorrect public key on the client: Ensure that the private key on your local machine (client) matches the public key on the virtual machine (see below)

  2. Incorrect username: Make sure you’re using the correct username for the virtual machine. The username should be the one associated with the public key in the ~/.ssh/authorized_keys file on the server. If using a Linux or Mac client, ensure you specified ubuntu or centos as username instead of the local username

To further troubleshoot the issue, you can use the -v (verbose) flag when running the SSH command. This will provide more information about the connection process and help you identify the cause of the problem:

ssh -v ubuntu@your_vm_ip

and check at what line the problem occurs, for example it will show which private key it served to the machine, and maybe it’s not the correct one. You can pick your correct private key by:

ssh -v -i PATH_TO_PRIVATE_KEY  ubuntu@your_vm_ip

Hope this can help you or others checking Discourse with a similar problem

Best wishes

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.