Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenSSH SSH-2 private key (old PEM format) on Azure Linux VM

I've been using Puttygen to generate SSH Key pair for Azure Linux VM. recently i found openssh is available on Windows 10 and i can use "ssh-keygen" command on Windows 10 CMD and generate Private and Public Key.

I've tried this but with unsuccessful attempt.

As per the article click here ask us to use below command and it completes successfully. It exports private and public key in a location. But when i load the private key in putty and connect to my server it throws error

Unable to use key file "C:\publickey\id_rsa.ppk" (OpenSSH SSH-2 private key (old PEM format))
login as:

Below is the command which i used to generate key pairs on windows 10

C:\Users\xxx>ssh-keygen -t rsa -b 2048 -C "azureuser@vm"
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\xxx/.ssh/id_rsa): C:\publickey\id_rsa.ppk
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\publickey\id_rsa.ppk.
Your public key has been saved in C:\publickey\id_rsa.ppk.pub.
The key fingerprint is:

Has anyone tried this method on windows 10 to generate keys?

like image 382
aquib.qureshi Avatar asked Mar 27 '20 10:03

aquib.qureshi


People also ask

Which SSH key is stored in Azure for Linux virtual machines?

Azure currently supports SSH protocol 2 (SSH-2) RSA public-private key pairs with a minimum length of 2048 bits. Other key formats such as ED25519 and ECDSA are not supported.

What is the format of OpenSSH private key?

So, the OpenSSH private key format ultimately contains a private key encrypted with a non-standard version of PBKDF2 that uses bcrypt as its core hash function. The structure that contains the key is not ASN. 1, even though it's base64 encoded and wrapped between header and footer that are similar to the PEM ones.


2 Answers

You've used ssh-keygen to create a private key file called id_rsa.ppk. However this is an OpenSSH-format private key and needs to be converted to Putty's own format to use in Putty.

Your options are:

  1. Use this key with command-line SSH (it's in the correct format). You can either
    1. specify the file on the command line e.g. ssh -i id_rsa.ppk azureuser@vm
    2. make a folder C:\Users\Aquib\.ssh and move it there as C:\Users\Aquib\.ssh\id_rsa (no extension): ssh will now load this file by default to use for all servers that you try to connect to
    3. if you don't want to use this for all servers, or e.g. if you already have a default id_rsa that you use with git, you can set up a C:\Users\Aquib\.ssh\config file that tells SSH where to find the key and tell it which servers it should use it for.
  2. Convert this file into the right format to use with Putty:
    1. In Puttygen, in the 'Conversions' menu choose 'Import' and load id_rsa.ppk
    2. 'Save private key' to a different file
    3. Use this new file with Putty, either on the connection properties menu or run Pageant (the Putty key agent) and 'Add key' the new file. (You can e.g. create a shortcut to pageant in your Startup menu and give it the key file name as a commandline parameter so this is loaded automatically for you.)
like image 120
Rup Avatar answered Sep 22 '22 17:09

Rup


For Linux (for example Ubuntu) you can install the command line puttygen like this:

# sudo apt install putty-tools

... and generate from your local ssh-key id_rsa to putty version id_rsa.ppk like this:

# puttygen id_rsa -O private -o id_rsa.ppk
like image 38
thoredge Avatar answered Sep 23 '22 17:09

thoredge