Log in to Linux virtual machine from Windows operating system

Victor Bonnet
7 min readMay 23, 2022

With WinSCP and PuTTY

When working with virtual machines it may be a need to connect to it to execute commands or transfert files. This article is to remember how to log in to virtual machines hosted on Google Cloud Platform and Microsoft Azure from a Windows operating system.

Here are two softwares to do it:

  • WinSCP: allows to have a file explorer inside the virtual machine which is useful to transfert files and folders. Download it here
  • PuTTY: the well-known SSH client, it opens a terminal to execute commands inside the virtual machine. Download it here

Install one of these softwares or both for the next steps.

1. Connect to a Google Cloud Platform virtual machine

To connect to a virtual machine hosted on Google Cloud Platform from a Windows operating system, we need to create SSH Key pair and associate them to the virtual machine.

To do this, open the command prompt in Windows by writing cmd in the search bar:

In the terminal that opens, write the following command:

ssh-keygen -t rsa -f [KEY_PATH]/[KEY_NAME] -C [VM_USERNAME] -b 2048
  • KEY_PATH: the path where the keys will be saved
  • KEY_NAME: the keys name
  • VM_USERNAME: the username the key will be associated to
# For example
ssh-keygen -t rsa -f C:\Users\Public\Documents\mysshkey -C gcpuser -b 2048

You will be prompted to enter a passphrase — which can be left empty or chose a password.

This command generates two files:

  • the public key ending with (.pub)
  • the private key with no extension

Note that the tools to connect to a virtual machine from a Windows operating system — WinSCP and PuTTY — use a private key in a specific format: PuTTY Private Key (.ppk) format.

The private key generated with ssh-keygen command need to be converted in the right format and will not work as it is. This conversion can be done with WinSCP as described below or with PuTTYgen tool available here.

1.1. Association with Google Cloud Platform

Now the keys are created it is necessary to associate the public key to the virtual machine on Google Cloud Platform

  • In Google Cloud Platform, go to Compute Engine
  • Under Settings, select Metadata
  • Select the SSH KEYS tab
  • Click EDIT
  • Add an item by clicking +Add item
  • In the field that appears, enter the content of the public key previously created (the one ending with .pub)
  • Click Save

Now this key is associated with the existing virtual machine(s) and will be associated with any virtual machines created later in the same project.

1.2. Log in with WinSCP

Open WinSCP to open a file explorer inside the virtual machine:

  • Click on New Session tab
  • Host name field: paste the External IP address of the virtual machine
  • User name field: write the username chosen when creating the key pair, leave it blank if no username was provided
  • Port number field: keep 22
  • Password field: Write the password if you have set one when creating the key pair, leave it blank if no password was provided

Then click on Advanced button:

  • Select Authentication under SSH menu
  • Click on the three points in the Authentication parameters block
  • Allow to show All files (*.*)
  • Browse and select the private key previously created (the one that has no extension)
  • Click OK when prompted to convert the OpenSSH private key to PuTTY format
  • Confirm in the next prompt by clicking Save
  • In the Advanced Site Settings window click OK to finish

In the login window click Login and a file explorer inside the virtual machine should open.

1.3. Log in with PuTTY

Open PuTTY to open a terminal inside the virtual machine:

  • Host Name field: enter the External IP of the virtual machine

Next a private key in a specific format (.ppk) is needed. However, the ssh-keygen command has created an OpenSSH private key (the key that has no extension).

Thus, thing to do is to convert the OpenSSH private key into a PuTTY format.

There are two ways to do it:

  • With WinSCP as described above
  • With PuTTYgen which can be downloaded here — instructions on how to use it are available on the website

Once the PuTTY formated private key (.ppk) is created, load it into the Auth menu of PuTTY interface:

  • Then Click Open

A terminal should open logged into the virtual machine.

Note that you may be asked to provide the username used at key pairs creation to log in to the virtual machine.

To provide username directly in PuTTY inputs, the format is the following:

2. Connect to a Microsoft Azure virtual machine

To log in to a Microsoft Azure virtual machine, by default there are less steps to do than in Google Cloud Platform as the key pair can be automatically generated at virtual machine creation.

When creating an Azure virtual machine resource, the default parameters about the connection part are set as follow:

  • SSH public key selected as the Authentication type
  • azureuser as the username
  • inbound port 22 opened

Then after clicking on the Review + create button:

a popup asks to download the generated private key in (.pem) format:

Note that the public key is automatically created in the SSH key zone in Azure and is linked to the Resource group.

The same key can be associated to any new virtual machine created later in the same Resource group at virtual machine creation as described below:

So now the Azure virtual machine is created and the private key in (.pem) format is downloaded, it is possible to connect to it with WinSCP and PuTTY.

2.1. Log in with WinSCP

Follow the steps described above for Google Cloud Platform.

  • Open WinSCP
  • Host Name field: Enter the public ip of the Azure virtual machine
  • User name field: Enter azureuser (or the correct username if changed)
  • Advanced Site Setting window: Select the downloaded (.pem) private key and accept the conversion from (.pem) format to (.ppk) format

Then click Login to connect which will open a file explorer inside the virtual machine.

2.2. Log in with PuTTY

Follow the steps described above for Google Cloud Platform.

  • Open PuTTY
  • Host Name field: Enter the public ip of the Azure virtual machine

Same as before, a (.ppk) private key is needed to use with PuTTY but here the private key provided by Azure is in (.pem) format which is not the correct format for these needs.

The thing to do is to convert it. Two ways to do it:

  • With WinSCP as described above
  • With PuTTYgen from here — instructions on how to use it are available on the website

Once the PuTTY formated private key (.ppk) is created, load it into the Auth menu of PuTTY interface:

  • Then Click Open

A terminal should open logged into the Virtual Machine.

Note: when asked about the username, azureuser is the default in Azure.

Thanks for reading the article. Please clap if you like it and feel free to comment if there are errors.

--

--

Victor Bonnet

Learning Data engineering, Cloud computing and data science after 10 years as structural engineer in aeronautics