The purpose of this exercise is to practice with using public/private key pairs to log in to your cloud instance.
Obtain a ssh client for your local computer. If you have a Mac or Linux system, there is already a command line ssh client built in. If you have a Windows system, a simple free option is putty and puttygenLinks to an external site.. Or, for a slightly nicer environment, I use
MobaXTermLinks to an external site.
. Get the portable versions if you do not have administrator rights to install software on the computer you are using.
Start your Cloud Console and start your instance. Click on the SSH link to log in.
Keep a Word document with the answers to the marked questions and with screenshots as required.
On your instance, look in the file ~/.ssh/authorized_keys, which contains PUBLIC keys of people allowed to log into your account. Note the general format of an entry, especially the comment #Added by Google. If you don’t see this file, logoff from your instance and then log back on. The file will be there then.
The general steps to this assignment, and to using public/private keys to access a system are to
Note that rather than do step 2 directly, we’re going to add it to the GCP configuration and let GCP update the file on the instance automatically as needed. You should not be changing any files on your instance for this exercise.
On a PC, using MobaXterm/Tools/MobaKeyGen or puttygen (see image)
See the section on
Linux/Mac
Adding a public key to GCP
As far as a Linux instance is concerned, the file ~/.ssh/authorized_keys controls access to the instance. However, GCP wants to manage this file itself. One way it does that is through metadata. Click on the metadata item in Cloud Console, then SSH keys. You should see some keys allowing you to log into any instance in your project. If you don’t see these, start an SSH session, then return to this page in GCP.
Notice that the keys specify the username for the account the key works with. Your first task is to add your own key you can use to log into your account directly from your PC without going through GCP. Once you click Edit, you can add or delete ssh keys, but not change them. Click Add Item, then copy/paste the public key you generated above into the space provided. The system will use the last item in the ssh key as the user name, as in the key at the bottom of the figure below, so be sure to change it to your GCP username.
Watch out for line breaks in the key that you paste. There shouldn’t be any, though they can sneak in based on the way you do your copy.
Login from PC
Login from Linux/Mac
ssh username@IPaddress –i privatekeyfile
Once you have logged in to you existing account,
Repeat the key generation steps and add another key to your GCP project. This time, change the username to something different. If your username is AlfredENeuman, then use the new username CS369AlfredENeuman. Take a screenshot that shows your keys in the metadata section. Be sure to show the username.
Log into your instance using this second key. Taks a screenshot showing you’ve logged in, then look at the last few lines of your /etc/passwd file. What is there that wasn’t there before!?
Explain in your Word document what Google’s infrastructure did under the hood that enabled you to log in with this second generated key pair.
At the end of your Words document, include the answers to the following questions:
For documentation, you should submit your Word document to Canvas.
Unit 5: Homework 2 Rubric
Criteria | Ratings | Pts | ||
---|---|---|---|---|
This criterion is linked to a Learning OutcomeLook at your authorized users file |
5 pts |
|||
This criterion is linked to a Learning OutcomeGenerate key pair and add public key to GCP metadata to log into your normal account |
5 ptsAll steps completed with successful login2 ptsCorrect metadata, including username, but no login, |
3 pts |
||
This criterion is linked to a Learning OutcomeGenerate key pair and add public key to GCP metadata to log into a new account |
||||
This criterion is linked to a Learning OutcomeExplanation of GCP behavior |
7 pts |
|||
This criterion is linked to a Learning OutcomeReflection |
3 ptsAll questions answered1 ptsOne point for each answer | |||
Total Points: 25 |