Secure Cloud Computing: How to Deploy and Connect to a Google Cloud VM

Pre-requisites
Have a Google Cloud (GCP) account
Some knowledge of SSH and how it works
Step 1: Create SSH keys
We will connect to a GCP virtual server using SSH to ensure secure communication between our local environment and the remote virtual server.
$ ssh-keygen -t ed25519 -C "containers"
This command will generate an SSH key pair. To learn more, visit this page.
Step 2: Create a new GCP project
On the console, create a new project to create the Google Compute Engine (GCE) virtual server, that we will connect to later.
Step 3: Configure a virtual network
We need to create a Google VPC network. From the console go to the VPC networks page, and click Create VPC network
. Name the VPC something like "container-vpc", and select the Automatic subnet creation mode, which only supports IPv4. Don't worry about firewall rules (later step), and click Create
.
Step 4: Create a firewall
Once the virtual network has been created, a firewall rule needs to be created and configured to allow inbound SSH traffic.
In our case, we can create a firewall rule named allow-inbound-ssh-traffic
which allows traffic from anywhere using 0.0.0.0/0
as the IP range, and ssh
as the allowed protocol.
Step 5: Start a new VM instance
When creating a VM on Google Cloud, choosing E2 instances is recommended for standard workloads like web servers, small-to-medium databases, development environments, and microservices that don't require specific hardware features.
In terms of settings, it's important to attach the network created in step 3 to the new instance. For this lab, we have created a Ubuntu LTS 20.04 server, and configured the SSH key created in step 1. Once the settings are finished, we start the instance.
Step 6: Test connectivity
We could connect to the new instance using Google's SSH-in-browser
feature. However, this in-browser temrinal may not offer all the features we would use when remote managing a VM server.
$ ssh <username>@<public_ip>
The authenticity of host 'xx.xx.xxx.xx' can't be
established.
ECDSA key fingerprint is
SHA256: <some text>
Are you sure you want to continue connecting (yes/no/[fingerprint])?
$ yes
This last step should connect us to our remote cloud-hosted Ubuntu server.
user@ubuntu:~$
Subscribe to my newsletter
Read articles from Bernie Camejo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
