by Nezar Assawiel
Google Cloud offers many tools and services. One of these services is creating highly customizable virtual machines. If you are not familiar with what a virtual machine is, here is a definition from Microsoft:
How to Generate SSH Keys on PuTTY. SSH keys are one of the most secure SSH authentication options. It is definitely more secure than the usual SSH password authentication. Therefore, it is highly recommended to use SSH Key authentication method for connections to your servers. Quick steps: Create and use an SSH public-private key pair for Linux VMs in Azure.; 4 minutes to read +4; In this article. With a secure shell (SSH) key pair, you can create virtual machines (VMs) in Azure that use SSH keys for authentication, eliminating the need for passwords to sign in.
This tutorial will show you how to generate and secure SSH keys on macOS Sierra (10.12) and macOS High Sierra (10.13). SSH keys allow you to log into your server without a password. They increase convenience as well as security by being significantly more resistant to brute-force attacks. Sep 15, 2014 The Secure SHell (SSH) command line is available through a Mac using the Terminal application. A private and public key pair is required before you can connect to the server. These instructions are for use with a shared server. Learn more about.
A virtual machine is a computer file, typically called an image, that behaves like an actual computer. In other words, creating a computer within a computer. It runs in a window, much like any other program, giving the end user the same experience on a virtual machine as they would have on the host operating system itself. The virtual machine is sandboxed from the rest of the system, meaning that the software inside a virtual machine can’t escape or tamper with the computer itself.
Virtual machines are needed in many situations to test applications against other operating systems, to access virus-infected data, or to experiment with other operating systems. You can install virtual machines on your computer. You can also create them in the cloud and simply connect to them.
In this tutorial, I will walk you through how to create a virtual machine in Google Cloud. We can connect to it with SSH from your computer.
- If you don’t have one already, create a Google Cloud account from here.
You will get $300 credit to play around with for a year! It is more than enough to learn and play with everything Google Cloud offers.
2.Create a new project or use an existing one. You can create a new project called project1, for example, as in the following gif:
3. Now you are set to create a virtual machine. Go to the top left corner of your Google Cloud home page, click on the triple bar icon ≡ and select Compute Engine ->VM instance and click Create.
Enter whatever name you want in the Name field as shown below:
Keep the default region and zone. Any region/zone will do for this tutorial. If you are curious about what they mean, you can read Google Cloud’s documentation about them here.
You can keep default machine type or click Customize toselect the number of CPU cores, memory, and GPUs you would like your virtual machine to have. You will see the cost on the right side changes!
For your first experiments with Google Cloud, you can be conservative with the $300 credit for some actual work. In such a case, you can choose the following configuration:
Next choose a boot disk. For example, you can choose 20 GB, SSD, Ubuntu 16.04 LTS as shown below:
Then set the Service Account under Identity and API access to No service account as shown below:
Finally, go to the Security tab under Firewall. You will see an SSH Key field as shown below:
This where you are going to connect your computer to the virtual machine using your SSH Key!
If you are not familiar with SSH (Secure Shell) and why you may want to use it, it is a network protocol that provides encrypted data communication between two computers (your computer and Google’s servers, in this case) which are connected over an insecure network (the Internet here).
To establish an SSH connection, you may need an application that can do that, depending on your operating system. Follow the rest of this post depending on your operating system (Windows or Mac/Linux).
Windows
I recommend PuTTY. It is an open-source and easy to use SSH client. You can download PuTTY and install it from here.
After installing PuTTY, open PuTTY Key Generator and click create. It will generate a random key by you moving the mouse over the blank area. After it is done, you will get something like this:
Change the key comment field to something recognizable and easy to type, as this will become a user name later!
Then save both the public and private keys by clicking the corresponding icons shown in the picture above.
Highlight the whole Key field from the PuTTY Key Generator, and copy and paste it in the key data field in Google Cloud:
Click create and wait for the virtual machine instance to be created.
In the meantime, you can go to PuTTY. Go to SSH ->Auth and browse for the private key file that you saved.
Next, go to Google Cloud and copy the external IP from the virtual machine instance that you just created as shown below:
And paste it on the Host field under Sessions in PuTTY and hit Enter:
Note: you might get an error message. Ignore it and click yes. (It just says the key is not already in the registry. Are you sure you want to connect?)
Then enter the username you created when generating the key (key comment above). Boom! you are in the virtual machine that you just created.
You can install python and Google APIs on it, for example, to start making some magic! Don’t forget to shut it down in Google Cloud after you are done to be economic with your credit :)
Mac/Linux
Mac and Linux support SSH connection natively. You just need to generate an SSH key pair (public key/private key) to connect securely to the virtual machine.
The private key is equivalent to a password. Thus, it is kept private, residing on your computer, and should not be shared with any entity. The public key is shared with the computer or server to which you want to establish the connection. To generate the SSH key pair to connect securely to the virtual machine, follow these steps:
Enter the following command in Terminal:
ssh-keygen -t rsa
. It will start the key generation process. You will be prompted to choose the location to store the SSH key pair. Press ENTER to accept the default location as shown below:Next, choose a password for your login to the virtual machine or hit ENTER if you wish not to use a password. The private key (i.e. identification) and the public key will be generated as shown below:
Now run the following command:
cat ~/.ssh/id_rsa.pub
. It will display the public key in the terminal as shown below. Highlight and copy this key:![Generate mac ssh keys for cloud vps login Generate mac ssh keys for cloud vps login](/uploads/1/2/5/8/125873880/534068263.jpg)
and paste it in the SSH key field in Google Cloud and hit Create:
Now you can use the External IP of the virtual machine you just created:
to ssh to it as follows:
You will get “The authenticity of host…etc.” warning as shown in the picture below. This is normal. Whenever SSH connects to a system it hasn’t seen before, it will generate a warning like this. Reply yes to connect, and bingo!You are in the virtual machine, as you can see from host name instance-3. To exit the virtual machine, just type exit.
Don’t forget to shut the virtual machine in Google Cloud after you are done to save that $300 credit!
Originally published at assawiel.com/blog on December 23, 2017. Updated: Oct 10, 2018
Verified and Tested 2/8/15
Introduction
This guide will show you how to generate and use SSH keys (public and private) using PuTTYgen and PuTTY for Linux servers.
How to Generate and Use an SSH Key
First thing’s first. We must generate our public and private keys using PuTTYgen. PuTTYgen and PuTTY can be downloaded here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Once they have been downloaded to a proper directory, open PuTTYgen first. Click on “Generate” to begin the key generation process. It will ask you to move your mouse around over the program window to help generate “random” data.
When the key is generated, the window will look like the picture below.
Sample public Key
Most of the information presented here is superfluous except in special instances. All you will want to do is update the “Key comment” box with a better friendly name for the key. Once you have done that, select all of the text in the “Key” box and paste it into Notepad or Notepad++ (preferred). Save that text file somewhere safe. You will also need to click “Save private key” on this window. Name it something useful and place it somewhere secure as well.
To use this key with a PuTTY connection, simply select the “Auth” menu on the left side of the program. This can be found under Connection -> SSH -> Auth. In this menu, there is a box titled “Private key file for authentication.” Click browse and find the .ppk file that you saved in the previous step.
At this point, if you name and save your connection in the “Session” category, you won’t ever have to follow this process again for that server/IP. Otherwise, you would need to choose your key each time you connect.
Generate Mac Ssh Keys For Cloud Vps Download
Creating a New Server with this SSH Key for Linux Servers
Creating a cloud server that uses an SSH key is simple. You will first need to setup your key in the cloud portal.
Click on “SSH Keys” on the left side under “Manage Servers.”
From there, click “Add SSH Key.”
When the window pops up, simply name your key, and paste the public key text (that you saved to a notepad file in a previous step) into the large box.
Cloud Portal:Add SSH Key
Click “Add Key.” If there were no issues with the key (inappropriate line breaks, errors, etc) it will save to the portal and be accessible for new servers.
To create a server that utilizes this key for root login, simply follow the “create server” steps found here.
Generate Mac Ssh Keys For Cloud Vps Login
-When choosing your server size and OS, you will see an option at the bottom that says “Pick SSH Key.” You will see the key we just created in that list. When the server comes online, simply use the previous PuTTY steps to connect to the server using that public key. The username will always be root when using our public key system.
Adding the Public SSH Key to an Existing Server
The steps for enabling public/private key login on a standard server that was not provisioned with a key originally is quite simple as well
Simply use PuTTY to log into the server as usual using the root account and password. You may already want to save a PuTTY profile with your key, even though the server will reject it until it is configured.
For all Linux-based operating systems, you only need to create root’s .ssh directory, and paste the public key into a file named “authorized_keys”
From here, you can either use a text editing program to paste the key in (vi/vim/nano, etc), or you can use echo. The echo command would look something like this:
At this point, you can log out of the server and log in using the previously stated method to open a PuTTY session with a private key attached. Upon entering the username “root”, the server should allow you to login without entering a password. If successful, you should see a message that states “Authenticating with public key.” The screenshot below has an example:
Sample Log in
Done! At this point, if you plan to access the server often, you will definitely want to save a profile. You can also setup a username to auto-login with under Data -> “Auto-login username.” Simply type root into that box and save it along with the private key and IP address to a PuTTY profile, and you can have instant passwordless login access to your server!
For more information about PuTTY, visit https://www.putty.org/.
For more information about PuTTYgen, visit https://www.puttygen.com/.
For more information about PuTTYgen, visit https://www.puttygen.com/.