How to connect to an existing Azure VM if my private key is not added to the VM?

Soundarya Ayyappan 61 Reputation points
2022-01-18T14:19:38.003+00:00

Consider a VM is already running in Azure. While creating the VM, I added the ssh public key which was generated in my machine. Now, my team member needs to access the VM, but while trying to access, we're getting the below error:

azureuser@<vm-ip>: Permission denied (publickey).

Since I didn't use "generate-new-key-pair" option while creating the VM, I don't have any pem file to provide to my team member for accessing the VM.

I followed the article https://learn.microsoft.com/en-us/azure/virtual-machines/ssh-keys-portal#generate-new-keys to generate new keys and downloaded a pem file. But unable to access the VM using the downloaded pem file (I guess because the key creation process nowhere included the VM related configuration).

So, can anyone please guide me on how to provide the VM accessibility to others in such scenario?

Thanks in Advance!

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

1 answer

Sort by: Most helpful
  1. srbhatta-MSFT 8,586 Reputation points Microsoft Employee
    2022-01-18T19:04:09.407+00:00

    Hello @Soundarya Ayyappan ,

    Thank you for reaching out to Microsoft Q&A platform.

    You can generate a new SSH key pair and have the private key downloaded (pem file) in your local machine, then use the Reset Password option in the Portal under the VM blade, and enter the username and the new public key to reset the SSH public key for the username.

    Post that, you can share the private key (pem file) with your team member and they can use it to ssh to the VM by using the below command.
    ssh <username>@<host> -i <private-key-path>

    166084-2022-01-19-00-26-05-clipboard.png

    I hope this helps.

    Please "Accept as Answer" if my answer helped so that it can help others in the community looking for remediation for similar issues.

    1 person found this answer helpful.

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.