Generating SSH keys for Linux on Windows Azure –updated

This is a modification to the post I did a while ago: Install openssl and edit OPENSSL_HOME before executing this script.

The following shell script will help generate the necessary keys for Window Azure Linux deployments on Windows 7 or Windows 8 clients:


@echo off
if "%1" == "" goto error

set x509_pvt_key_name=%1_x509_pvt.pem
set x509_pub_key_name=%1_x509_pub.pem
set RSA_pvt_key_name=%1_rsa_pvt.pem
if "%2" == "" goto nodes

%OPENSSL_HOME%\bin\openssl req -x509 -config %OPENSSL_HOME%\bin\openssl.cfg -days 365 -newkey rsa:2048 -keyout %x509_pvt_key_name% -out %x509_pub_key_name% -passout pass:%2
%OPENSSL_HOME%\bin\openssl rsa -in %x509_pvt_key_name% -passin pass:%2 -out %RSA_pvt_key_name% -des3 -passout pass:%2
echo generated %x509_pvt_key_name%, x509_pub_key_name and %RSA_pvt_key_name%
goto eof

%OPENSSL_HOME%\bin\openssl req -x509 -config %OPENSSL_HOME%\bin\openssl.cfg -days 365 -newkey rsa:2048 -keyout %x509_pvt_key_name% -out %x509_pub_key_name% -nodes
%OPENSSL_HOME%\bin\openssl rsa -in %x509_pvt_key_name% -out %RSA_pvt_key_name%
echo generated %x509_pvt_key_name%, x509_pub_key_name and %RSA_pvt_key_name%
goto eof

echo usage: gensshkey_win <key_prefix> <optional_pass_phrase>
echo key_prefix used to prefix the generated files; use a prefix that represent your key usage. Don't use any quotes around the args
echo example: gensshkey_win dbsrv pass@word1
echo example: gensshkey_win dbsrv

echo use %x509_pub_key_name% cert while creating Linux VM on Azure
echo use %RSA_pvt_key_name% cert to covert to ppk format using puttygen.exe. Use the .ppk file use putty.exe as the ssh client

All the keys generated are PEM (base-64) formatted with the suffix _rsa_pvt.pem meant for converting into .ppk format to be used inside putty.exe from
Windows. Assuming that our RSA formatted key is dbsrv_rsa_pvt.pem, this can be converted to .ppk format using the following sequence on puttygen.exe: Conversions –> Import key –> Save private key. Make sure to enter the pass phrase if you need to add additional measure of security to the SSH interaction.

Following are the examples of usage:

Example 1: Clear text private key

gensshkey_win dbsrv

Example 2: Clear text private key

gensshkey_win dbsrv pass@word1

While creating the Linux VM on Windows Azure, use the public key with the suffix _x509_pub.pem for SSH certificate.

Technorati Tags: Linux,Windows Azure,Linux on Windows Azure,SSH,openssl,generate ssh key on Windows