15

Googling was fruitless, as most people have a slightly different variation of this problem.

I am trying to setup an Azure Linux VM with SSH (no password), for access from a Windows machine. 2018 UPDATE: The original requirement was to use WinSCP but I'm ok with using Putty instead (on the Windows machine, which is the SSH Client) .

How can you set up an Azure Linux VM and generate the required keys using as few additional tools as possible, on Windows?

Alex R
  • 1,824
  • 6
  • 24
  • 46

5 Answers5

16

First you need get public key in a format for OpenSSH authorized_keys file.


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):

enter image description here

Martin Prikryl
  • 21,071
  • 9
  • 77
  • 157
  • 1
    That doesn't work. Azure goes through the initial stages of VM setup but then aborts complaining that the key is not X.509 compliant. – Alex R Jul 30 '14 at 18:49
  • 1
    Ok, I followed the instructions at http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-use-ssh-key/ 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 '15 at 04:49
  • 1
    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 '15 at 04:51
  • @RohitChatterjee That was all misunderstanding. OP asked about private key (giving an impression he want to use it as host key), while the question was actually about public key. I've updated my answer accordingly. – Martin Prikryl May 08 '18 at 19:38
  • Actually this is still a little off as I wanted to use WinSCP, not Putty. I'm going to edit the question one more time to make this answer correct. – Alex R May 08 '18 at 20:29
  • It's not off, as the procedure is the same for WinSCP and PuTTY. But anyway, I've added a note that WinSCP has its own copy of PuTTYgen, so you do not have to install it for this. – Martin Prikryl May 08 '18 at 21:02
  • Can you please remove your first comment starting *"That doesn't work"*? – Martin Prikryl Oct 19 '18 at 14:03
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

Alex R
  • 1,824
  • 6
  • 24
  • 46
1

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).

barlop
  • 23,380
  • 43
  • 145
  • 225
0

I see this is an older question, but if you're using Windows 10, it's now possible to SSH from the Windows Subsystem for Linux. For that, just set up keys like you would do in regular Linux.

Charles Burge
  • 2,100
  • 1
  • 8
  • 14
  • Is that this? https://www.howtogeek.com/336775/how-to-enable-and-use-windows-10s-built-in-ssh-commands/ Or maybe what is at that howtogeek link is an SSH outside of Windows subsystem for linux? (i'm still on Win7 myself!) – barlop Sep 17 '21 at 09:52
  • That should work, but what I was actually talking about is https://docs.microsoft.com/en-us/windows/wsl/install-win10. – Charles Burge Sep 18 '21 at 05:29
  • yeah I think we've established that you're talking about Win10's WSL(Windows Subsystem for Linux) !!! – barlop Sep 18 '21 at 11:20
0
  • On your windows machine, using Search > Apps & features > "Manage optional features" > "Add a Feature" option.
  • Install "OpenSSH Client" feature by either searching in the box or navigate on the descending alphabetic order of item list and select "Install" in the pop-up window.
  • Later it is successful, open either cmd prompt or powershell and type "ssh", if you see help menus, that means installation is successful.
  • Later open C:\Users\YourUsername\.ssh directory.
  • Paste the pubkey generated from Azure while deploying the Linux VM in this directory.
  • Now on command prompt or powershell, first navigate or cd to the same .ssh directory and then execute following command(I am showing CMD prompt example).

CMD> cd C:\Users\<YourCompUsername>\.ssh

CMD> ssh <azurevmusername>@azurevmPublicIP

OR

If you have created same username on Azure while deploying the VM.

CMD> ssh azurevmIP

And that is it! You are done.