How to Use SSH with Linux on Windows Azure
This topic describes the steps to generate SSH keys compatible with Windows Azure.
The current version of the Windows Azure Management Portal only accepts SSH public keys that are encapsulated in an X509 certificate. Follow the steps below to generate and use SSH keys with Windows Azure.
Get OpenSSL on Linux
To get openssl on a Linux machine, use the native package management solution for your Linux distribution:
- Redhat/CentOS:
yum install openssl - Debian:
apt-get install openssl - Ubuntu:
apt-get install openssl
Generate Windows Azure Compatible Keys in Linux
-
Use openssl to generate an X509 certificate with a 2048-bit RSA keypair. Please answer the few questions that the openssl prompts for (you may leave them blank). The content in these fields is not used by the platform.
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout myPrivateKey.key -out myCert.pem
-
Change the permissions on the private key to secure it.
chmod 600 myPrivateKey.key
-
Upload the myCert.pem while creating the Linux virtual machine. The provisioning process will automatically install the public key in this certificate into the authorized_keys file for the specified user in the virtual machine.
-
If you are going to use the API directly, and not use the Management Portal, convert the myCert.pem to myCert.cer (DER encoded X509 certificate) using the following command:
openssl x509 -outform der -in myCert.pem -out myCert.cer
Connect to an Windows Azure Virtual Machine from Linux
Every Linux virtual machine is provisioned with SSH in a particular port that may be different from the standard port used so you
- Find the port you will use to connect to the Linux virtual machine from the Management Portal.
-
Connect to the Linux virtual machine using ssh. You will be prompted to accept the fingerprint of the host's public key the first time you log in.
ssh -i myPrivateKey.key -p <port> username@servicename.cloudapp.net
- (Optional) You may copy
myPrivateKey.key to ~/.ssh/id_rsa so that your openssh client can automatically pick this up without the use of the -i option.
Get OpenSSL on Windows
Use msysgit
- Download and install msysgit from the following location: http://msysgit.github.com/
- Run
msys from the installed directory (example: c:\msysgit\msys.exe) - Change to the
bin directory by typing in cd bin
Use GitHub for Windows
- Download and install GitHub for Windows from the following location: http://windows.github.com/
- Run Git Shell from the Start Menu > All Programs > GitHub, Inc
Use cygwin
- Download and install Cygwin from the following location: http://cygwin.com/
- Ensure that the OpenSSL package and all of its dependencies are installed.
- Run
cygwin
Create a Private Key on Windows
- Follow one of the set of instructions above to be able to run
openssl.exe -
Type in the following command:
openssl.exe req -x509 -nodes -days 365 -newkey rsa:2048 -keyout myPrivateKey.key -out myCert.pem
-
Your screen should look like the following:

-
Answer the questions that are asked.
- It would have created two files:
myPrivateKey.key and myCert.pem. -
If you are going to use the API directly, and not use the Management Portal, convert the myCert.pem to myCert.cer (DER encoded X509 certificate) using the following command:
openssl.exe x509 -outform der -in myCert.pem -out myCert.cer
Create a PPK for Putty
- Download and install puttygen from the following location: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
- Run
puttygen.exe - Click the menu: File > Load a Private Key
- Find your private key, which we named
myPrivateKey.key. You will need to change the file filter to show All Files (*.*) -
Click Open. You will receive a prompt which should look like this:

-
Click OK.
-
Click Save Private Key, which is highlighted in the screenshot below:

-
Save the file as a PPK.
Use Putty to Connect to a Linux Machine
- Download and install putty from the following location: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
- Run putty.exe
-
Fill in the host name using the IP from the Management Portal.

-
Before selecting Open, click the Connection > SSH > Auth tab to choose your key. See the screenshot below for the field to fill in.

-
Click Open to connect to your virtual machine.