Can't login with ssh due to 'Permission denied (publickey)'.

Gawain Tan 5 Reputation points
2024-10-28T08:10:13.9733333+00:00

Can't access the VM though ssh. Always tell Permission denied (publickey), although I change the pub key many times. Also, adding a new user still doesn’t work. I can't log in to the serial console because the password is always wrong. I’ve reset the username and password many times. Everytime I use 'az cli' to reset password it stuck hours without any result. The server is still running, but I have no idea how to access it.

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

1 answer

Sort by: Most helpful
  1. Prrudram-MSFT 28,366 Reputation points Microsoft Employee Moderator
    2024-10-28T10:05:32.8266667+00:00

    Hello @Gawain Tan

    I see you are having trouble accessing your VM through SSH and resetting the password using the Azure CLI is not working for you.
    There could be several reasons why you are unable to access your VM through SSH. Let's try to troubleshoot the issue step by step.

    1. First, make sure that you are using the correct username and password or SSH key to connect to your VM. You can check the username and SSH key by going to the Azure portal and navigating to your VM's "Overview" page. Under "Connect", you can see the SSH command to connect to your VM. Make sure that you are using the correct username and SSH key.
    2. If you are still unable to connect, try resetting the SSH configuration on your VM. You can do this by using the VMAccess extension. The VMAccess extension can reset the SSH configuration and create a new user with sudo privileges. You can find more information about the VMAccess extension in the provided document.
    3. 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.
    4. 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.

    Please refer to the following document links

    https://learn.microsoft.com/en-us/troubleshoot/azure/virtual-machines/linux/troubleshoot-ssh-connection#reset-ssh-credentials-for-a-user

    https://learn.microsoft.com/en-us/troubleshoot/azure/virtual-machines/linux/troubleshoot-ssh-connection
    If you have any further questions or concerns, please tag me in your comments.


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.