Google Cloud VM Setup
Objective
To create a virtual machine running Linux on Google Cloud.
VM Creation
The Google Cloud platform is a service run by Google and offers things like data hosting and application support. It also offers virtual machines running Linux which is what we will use it for.
A virtual machine (VM) is a computer system which is run on top of another one. When we create a VM, it is just like having our own personal server. In actuality Google runs many VMs on one physical computer.
The following instructions will guide you through setting up a virtual machine on the Google Cloud:
- Redeem your student coupon from the email you were sent. This coupon will allow you to create virtual machines without having to enter credit card information. If you did not receive an email with this link, please let me know. To redeem the coupon, click the link, and enter your UMW email address. Then verify the address when you receive a message from Google.
Navigate to https://console.cloud.google.com. If you are not signed into Google, you will be prompted to do so. If you do not have a Google account, you will need to create one for this course. You should then see a screen like this:
You will need to create a "Project" first. Google cloud uses this to allow you to group related VMs together. You can call the project whatever you like, such as "CPSC 318". When you are done, make sure the project is selected (it should say the name you chose on the top of the screen).
Now we need to create our virtual machine. Click the Navigation menu in the upper left (the three white lines or "hamburger menu"). Then click on "Compute Engine". Then click the "Create Instance" button".
- Enter the following fields in the Machine Configuration Tab:
- Name: whatever you like
- Leave the region and zone as the defaults (don't change it to northern Virginia, even though that would make sense).
- Leave the series set to "E2".
- Change the machine type to "e2-micro". This is sufficient for our needs.
- Leave the rest as default.
- In the OS and Storage tab, we can leave the default 10 GB disk with Debian 12. If we needed more space, or wanted a different operating system, we could change that here.
- In the Networking tab, check the boxes to allow HTTP and HTTPS traffic.
- Click create.
Connection and Configuration
The first time we connect to our new VM has to be through the Google Cloud interface. Click the "SSH" button next to your VM. After a little while you should have a command prompt.
Now we will perform a couple of configuration changes.
- First we will set it up to allow us to login to the VM with a password. This way we can use
a separate SSH tool instead of the browser. To do this, type the
command:
$ sudo vim /etc/ssh/sshd_config
Hit enter, and then hit the down arrow until you get to a line which says:
PasswordAuthentication no
Change the "no" on that line to say "yes". Then save and quit. Then run the following command:
$ sudo systemctl restart ssh
This will restart the SSH server with the new setting.
We are now able to login with a password, but first we need to set a password. To do this, first observe that your username for the VM is the name of the Google account you used.
Then run the following command:
$ sudo passwd username
Of course replace username with your Google account user name. Note that the command
passwdis not the whole word password.After entering that command, you will be prompted to enter a password for the VM. When you enter the password it will not show up, not even as dots or stars. Just enter type your password and hit enter when done. You will be asked to retype it.
The next configuration change is to give our user administration privileges. To do this, enter the command:
$ sudo visudo
Then scroll down to the bottom of the file, and add the following line:
USER ALL = (ALL) NOPASSWD: ALL
except replace USER with your user name on the VM.
Then save and quit.
You can now close out of the SSH browser window by hitting Ctrl-D.
Connecting with a Client
Now you can connect from your computer's terminal directly. Open a terminal window and run the following command:
$ ssh user@ip
Where you replace "user" with your VM username (which is your gmail name), and "ip" with the IP address of the VM you created. It is listed in the VM instances page on Google cloud. Be sure to use the external IP and not the internal one!
Using a proper terminal will be much smoother than the web-based one.
Submitting
Run the following two commands to install cowsay and display a message:
$ sudo apt install cowsay $ echo "VM is ready to go" | cowsay
Take a screenshot of your terminal and submit it for this lab in Canvas.