Some time ago, I created an Ubuntu virtual machine in Azure using a password-based login. Over time, I got annoyed with having to enter the password each time I logged in, so I decided to switch over to using SSH public keys. Unfortunately, the Azure documentation regarding such a scenario assumes only that you will be creating a new virtual machine from scratch to create a public key based login. Have no fear. I have figured out how to do this without having to recreate your virtual machine.
- Linux-based client (your computer)
- Linux-based virtual machine in Azure with password-based login (Azure)
Create the RSA Keys on Your Computer
Azure requires RSA keys with 2048-bit encryption, so you should do this:
ssh-keygen -t rsa -b 2048
Just press ENTER when asked where to store the file unless you really want to put it somewhere other than the default. In most cases, the default is fine. After you pick the location, enter a good password to unlock the private key when prompted during login.
Transfer the Keys from Your Computer to Your Server
In order to copy your keys to the server on which you want to login, you will need to have a password-based login already setup. If this is your case, do the following:
Enter your server’s password-based login when prompted to begin the copying process.
Confirm Your Key Based Login Works
Do this and enter your previously created key’s decryption password: