Ssh – New VM Can’t connect SSH port 22 – Permission Denied

azurepowershellsshubuntu-18.04

I have a new Ubuntu 18 server in Azure. I am using PowerShell (with the 2018 SSH client already installed). I have tried Putty also. Both with PowerShell and Putty I typed in ssh username@ipaddress, type yes to accept and then I get Permission denied (publickey).

My Azure settings: no password required to log in, just Pub/Priv keys. I let Azure create the Keys so that must be done and stored correctly.

I think the issue is that I am not associating the private key, which is stored on my Windows 10 machine, properly. To be honest, I never tried to associate it. I don't know how to. Am I supposed to be in the directory where the key is when using PowerShell? I was never prompted for the private key anywhere.

Best Answer

When you creating new VM with generate key pair option, it should be downloaded on your drive (by default on Download folder). Then you need to insert privatekey.pem when connecting over ssh by adding -i attribute :

ssh -i keypair.pem azureuser@x.x.x.x
#or
ssh -i C:\pathtofolder\keypair.pem azureuser@x.x.x.x

But if you forgot or lost your keypair from azure. you can create new one using puttygen. Complete guide you can see in https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/create-with-putty/

  1. Download and open puttygen. click generate and move your mouse randomly on the blank area until finish
  2. Save Private key on your machine, and copy public key
  3. go to azure, choose your VM. in left menu, choose Reset password and use public key option. then paste your public key Reset Password / SSH public key

4. it will create new user or updating the existing one 5. Double-click previously saved private key from puttygen, it will run as background service 6. Now you can ssh without adding -i attribute

Related Topic