Create an OCI Compute Instance and connect to it via SSH using PuTTY
There are so many articles out there on how to use PuTTY to connect via SSH to a Linux Machine on Cloud so why another one? this one simply works.
UPDATE September 2020: You can now let OCI generate the private/public key par for you so you won’t encounter any issues! You just can also download the keys and store them securely on your laptop.
I’ve been working with cloud compute instances for a long time using Linux machines or macOS and it was very easy and effective. Of course, I heard many times the possibility of using PuTTY on Windows and I didn’t put too many thoughts on that because 1) I didn’t need it and 2) How difficult can it be? I mean, using SSH on a bash shell is really a piece of cake.
So you can imagine how surprised I was when I used Putty for the first time… A complete mess of file formats and errors.
I need it to figure out how to make it work for a windows environment so, PuTTY was the simplest way.
Note: Recently, a bash shell for windows has been released on Windows Store and it simply amazing but, for many reasons, Putty may still be the fastest/easiest choice.
Problem: Public Key format
Quick and simple: you cannot just save the Public key using the Save Public Key button. The format in which Putty saves the key may not be fully compatible with every cloud environment.
You will need to copy the ssh key text and save it as shown later in the guide.
So in the following part of this article, I will show you how to generate a Public/Private key pair with PuTTYGen, then create a Compute Instance on Oracle Cloud Infrastructure and finally connect to it using Putty.
Generate Public/Private Key Pair using PuTTYGen
First of all, you can download PuTTY from here. I strongly advise you to download the version that includes PuTTYGen, the key generator software.
Once installed you will find the PuTTYGen and by opening it you will find a window like the one below.
Make sure every setting match the screenshot and click on generate. You will be asked to move the mouse on the blank area to generate so entropy and once the key pair will be ready you’ll find a screenshot similar to the following one on the right.
You will need to select all the text that begins with ssh-rsa and copy it on a blank page of a text editor. You will need to save it with a .pub extension as shown below.
Secondly, you can save the private key file by clicking on the “Save Private Key” button on PuTTYGen
Ok we now have a public key with a .pub extension and a private key with a .ppk extension. we are now ready to create a Linux instance on OCI.
Just log into your Oracle Cloud Infrastructure account and from the hamburger menu on the left chose Compute -> Instances as shown below.
Note: If you don’t have an Oracle Cloud account you can create Free Trial / Free Tier by clicking here.
Once you are in the instances section, click on the blue button that says “Create Instance”. You will be prompt to the create Instance page where you can select the shape and the image that you want to have. Make sure you have selected the Radio Button that says “Assign a Public IP address” so that the machine will be accessible from the outside.
At the end of the Create Instance page, you are gonna be asked to insert or paste the public ssh key. You can now select the public key that we saved earlier.
It will take almost a minute to create the machine and by clicking on the Instance Name you will be brought to the Instance’d details page where you’ll find the machine Public IP address.
Ok, we are now ready to connect to it using PuTTY.
Open PuTTY and insert the Public IP address on the Hostname field.
Then, from the menu on the left side move to SSH, click on the little + sign and select Auth as shown below.
You can now select the private key file that we saved before with the .ppk extension and click “Open” to start a session.
Now, if the machine can be reached you will be shown a window like the one below, click on Yes and you’ll be asked to insert the Username to login.
Now, if you selected an Ubuntu machine the default username will be “ubuntu” while if you selected an Oracle Linux machine or an Autonomous Linux image, you will need to insert the “opc” username and press enter.
If the connection will be successful you’ll have a screenshot like the one above.