I created a Linux Virtual Machine in Azure, but connecting to it through SSH was a real nightmare. I was always getting the below error -
"Permission denied (publickey)."
After lot of googling, binging and shooting in the dark, this is how I fixed the problem:
- Create a new ssh key by running below command.
ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/<Username>/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/<Username>/.ssh/id_rsa.
Your public key has been saved in /c/Users/<Username>/.ssh/id_rsa.pub
Enter file in which to save the key (/c/Users/<Username>/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/<Username>/.ssh/id_rsa.
Your public key has been saved in /c/Users/<Username>/.ssh/id_rsa.pub
- In Azure portal. Click on your Virtual Machine name,
- Select 'Reset Password -> 'Reset SSH' -> 'Reset SSH public key'
- Type Username for VM
- Open 'id_rsa.pub' public key in an editor, copy it's content and paste it in SSH public key text box.
- Now try connecting again to VM from command line tool such as Git Bash
- ssh <user>@<public_ip_of_your_linux_vm>
- It worked! This time I saw the below output.
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.15.0-1014-azure x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical. com
* Support: https://ubuntu.com/advantage
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/ business/services/cloud
0 packages can be updated.
0 updates are security updates
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.
* Support: https://ubuntu.com/advantage
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/
0 packages can be updated.
0 updates are security updates
.......................
.......................
Comments