Azure SSH Keys Don't Work? Permission denied (publickey).

James Lynch 0 Reputation points
2024-12-13T03:17:41.43+00:00

Hi, I used the web portal to generate new ssh keys for my Ubuntu 22.04 server.

I downloaded the .pem, added it to my local keychain, and ssh'ed into the server.

Then I came back a few hours later and ran the same command, but now I get the error "Permission denied (publickey)". Even after I go into the portal and try to reset the key,

download it, add to it my keychain, I STILL get the error when I try to ssh.

Running this command (with my ip instead of the xs)

ssh -i ~/.ssh/second-try-key.pem ******@xxx.xxx.xxx.xxx

And it gives me this error:

******@xxx.xxx.xxx.xxx: Permission denied (publickey).

I think the error means the server is not accepting this key, right?

Am I doing something wrong here??

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,068 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Mounika Reddy Anumandla 6,940 Reputation points Microsoft External Staff Moderator
    2024-12-13T05:20:01.0633333+00:00

    Hi James Lynch,

    Welcome to Microsoft Q&A Platform, thanks for posting your query here.

    As per the details shared, you are trying to sign in to your VM but SSH failed with permission denied (public key) error message.

    To resolve this issue please follow the below steps:

    Reset the SSH configuration.

    You can reset the SSH public key by using the below option on Azure portal, you can provide a new public key by generating a new key combination on putty gen.

    266945-image.png

    Once this this done, verify the network security group rules permit SSH traffic:

    Please Ensure that a Network Security Group rule exists to permit SSH traffic (by default, TCP port 22). You can also use this link, and see if 22 port on public IP is open or not.

    266869-image.png

    Restart the VM to ensure changes are in effect.

    If resetting the SSH configuration does not work, you can try accessing your VM through the serial console. The serial console allows you to access your VM's console output and perform troubleshooting steps. You can find more information about accessing your VM through the serial console in the provided document.

    If you are still unable to access your VM, you can try creating a new VM and attaching the disk from the old VM to the new VM. This will allow you to access the data on the disk without having to access the old VM. You can find more information about attaching a disk to a new VM in the provided document. I hope this helps you to troubleshoot the issue.
    https://learn.microsoft.com/en-us/troubleshoot/azure/virtual-machines/linux/troubleshoot-ssh-connection

    Hope this helps. If you need further help on this, tag me in a comment. If the suggested response helped you resolve your issue, please 'Accept as answer', so that it can help others in the community looking for help on similar topics.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.