How to connect the local computer to GCP using SSH
This post was inspired by a challenge I faced during my weekly learning task, wrote this because the materials I used were scattered I thought that I’d write about it here.
I completed this task using a MacBook
Start with opening a Google Cloud Platform (GCP) account, the link below will help
https://www.youtube.com/watch?v=hRXMuMQQ27c
Then move on to generate ssh key
Using ‘ssh-keygen’ then run the command in terminal
It will ask where we want to save the key and what file we want to save as
The default is going to be wherever our home directory for our logged in user and ‘.ssh’ which is going to be a hidden folder by default and the file name will be ‘id_rsa’ that’s going to be the name of the private and public key difference Is that the public key will just be ‘id_ras.pub’
We can just use the default by pressing enter
It will prompt for a passphrase which you can also decide not to have one by clicking enter two (2) times it will be asked
This should create your key
If you want to see your key you can ‘ls .ssh’
We can see both the public key and private key
If we want to see what’s in our public key we can use the cat command
The above is what our public key will look like the private key is longer, but we will only be using the public key
Adding your ssh key to the ssh-agent
Start the ssh-agent in the background.
First, check to see if our ‘~/.ssh/config’ file exists in the default location.
If we see this ‘.ssh/config’ does not exist. don’t be scared we are still on the path
If the file doesn’t exist, create the file.
Let’s open our ‘~/.ssh/config’ file, then modify the file, replacing ‘~/.ssh/id_rsa’ if we are not using the default location and name for our ‘id_rsa’ key.
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
Let's add our SSH private key to the ssh-agent and store our passphrase in the keychain. If we created our key with a different name, or if we are adding an existing key that has a different name, replace ‘id_rsa’ in the command with the name of our private key file.
How to copy our public ssh key
Then we can just paste, where our ssh key is required in our instance on GCP.
Now we have this key on our local system and we have added our ssh key to ssh-agent we can now get it on our Google Cloud Platform (GCP)
This link will help with that
https://www.youtube.com/watch?v=JGcW1QdEQGs
NOW lets ssh into our GCP instance
After pasting our public ssh key
Make sure we copy the External IP address
Let’s go back to our terminal
SSH into our instance with the copied External IP address
The output will be like the code snippet below after we are prompted and yes is entered
Watch out for my weekly series
THE JOURNEY TO THE CLOUD
This will be about my weekly tasks and the resources I used to execute them