How to setup SSH Keys on Windows machine (SSH Client) to access Azure Linux VM?
Solution 1:
First you need get public key in a format for OpenSSH authorized_keys
file.
-
In WinSCP 5.15, you can use Display Public key on SSH > Authentication page of Advanced Site Settings dialog:
-
Or you can use PuTTYgen - It's a part of PuTTY package, but WinSCP comes with its own copy (use Tools > Run PuTTYgen on WinSCP Login dialog).
Start PuTTYgen.
Load your private key in
.ppk
format.-
Copy the contents of the box labeled "Public key for pasting into OpenSSH authorized_keys files" to the clipboard:
Once you get the public key in the authorized_keys
format, paste it to the "SSH public key" box, when provisioning Azure Linux machine (or when resetting the public key):
Solution 2:
The correct answer was provided in comments by @Rohit Chatterjee:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout myPrivateKey.key -out myCert.pem
Explanation:
The Azure portal asks for a PEM / CER as part of the VM provisioning process (though one can provide a password instead). PuttyGen creates a PEM from a PPK as this answer decribes, but the output is not accepted by the portal. If I figure this out I will post an answer here... – Rohit Chatterjee Jan 29 at 4:18 1 up voted
Ok, I followed the instructions at azure.microsoft.com/en-us/documentation/articles/… and they worked. Basically you run "openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout myPrivateKey.key -out myCert.pem". The .pem needs to be uploaded via the Azure portal. (I'm not posting this as an answer because I did it on my Mac, and the poster asked for a Windows solution. Googling indicates that OpenSSL distributions for Windows exist, but I haven't tried any.) – Rohit Chatterjee Jan 29 at 4:49
Also, the private key generated in my comment above - myPrivateKey.key - needs to be imported into PuttyGen and converted to a PPK. Putty will not use the .key file. – Rohit Chatterjee Jan 29 at 4:51
Solution 3:
I would suggest on Windows, using an SSH command, one way or another. So for example from my windows 7 machine, I tend to use Cygwin and that has openssh. And I can run the ssh command from there, or start an sshd server via cygwin.
Even if I do decide to use a GUI program, I want to have it working via command line as that's really the foundation of SSH. GUI programs make it trickier to see what's going on and what's where. The command line is more consistent. What a Windows GUI program can be offer is on the server side e.g. a GUI program I did use, offered at the server end, a regular windows style command prompt when SSHing into it. Maybe was WinSCP
Windows 10 apparently has an SSH built in that is optional on installation, and that can be added in or after installation. https://www.howtogeek.com/336775/how-to-enable-and-use-windows-10s-built-in-ssh-commands/ (and there's also Win10's WSL that includes SSH).