Take Full Control of AI Notebook Instance on GCP via Putty
By: Phillip Peng
Tags: Localhost, Google Cloud Platform, Putty, AI, Jupyter Notebook

access GCP VM instance via Putty for cloud computing

AI notebook instance on GCP runs on a VM instance. If we can access the VM instance via Putty, we can then have full control of the VM instance through Linux commands. In this post, I am going to walk through how to set up access to the AI notebook instance on GCP via Putty.

1. Start the VM instance.

One way to start an AI notebook instance is to use the GCP cloud console. The AI notebook instance runs on a VM instance with the same name. Another way is to use “gcloud SDK,” which I manage from ‘Windows Terminal.’ (My other post on why you shall use ‘windows Terminal’). The command to start the VM instance is:

gcloud compute instances start INSTANCE-NAME

2. Add an external IP address to the VM instance on GCP.

From the Navigation Menu in the GCP cloud console, you can navigate to the Compute Engine (GCE) list as below:

Click the three-dot icon on the most right side of the selected GCE VM instance, select ‘view network details’ to navigate to the following VPC network configuration screen:

We will select the ‘External IP addresses’ tab. There are two possible Types: Static and Ephemeral. For VM instances, static external IP addresses remain the same until they are removed. The Ephemeral external IP addresses will change every time when you start the instance. We will set the external IP address as ‘Static’ as we need to use the same information to login in the future.

3. Add the ssh key to the VM instance on GCP.

First, we generate the ssh key pair (public key and private key) using PuTTYgen.

The ‘key comment’ part will be the user name and ‘Key passphrase’ will serve as the password for later logins. We shall save the public key and private key. The public key file name follows the format of starting with ‘ssh-rsa’ and ending with the key comment which serves as the user name.

Once we generate the ssh key pair, we can go to the VM instance detail in the console, click the ‘EDIT’ button, and scroll down to the ‘SSH Keys’ section as the screenshot below:

(SSH Keys for GCE VM instances)

Expand the ‘Show and edit’ option to add the ssh public key to the VM instance.

4. Configure Putty to connect to the VM instance on GCP

Start program ‘PuTTY’ and select the Session category at the left side of the panel as below:

In the Host Name (or IP address) box, we use the Static external IP address added to the VM instance in step 2. To avoid type the user name every time, we add ‘user_name@’ before the IP address. We also save this information so that we can just load the stored session later to save the work of typing the configuration settings.

Next, we go to the Category/Connection/SSH/Auth to load the private key file.

Last, we specify the ports to be used for AI notebook instances at the ‘Category/Connection/SSH/Auth/Tunnels.’ As we know, the Jupyter notebook on the local machine will use port 8888. To avoid port conflicts, we use port=7080 (non-8888 port) for our PuTTY remote connection. By clicking the ‘Add’ button, port=7080 will be shown in the “Forwarded ports” box. We can now go back to the session part and save the updated settings. Once clicking the ‘Open’ button, we will navigate to the PuTTY login screen.

5. Start AI notebook from localhost.

Once we log into the VM instance via PuTTY, we can activate the AI notebook runtime environment and start Jupyter Notebook or Jupyterlab.

conda activate base

cd /

jupyter notebook --port=7080

The base environment is the one used by the AI notebook instance. we can create new environments in addition to the base environment as needed. Command-line ‘cd /’ navigates us to the root directory. Remember to add the part “- -port=7080” when we start the Jupyter notebook.

Now, let’s open a browser and type the address ‘localhost:7080’ to start to use the Jupyter Notebook or ‘localhost:7080/lab’ to start to use JupyterLab.