Handle multiple Google Cloud Shell using Windows Terminal

Aldo Loria
Google Cloud - Community
3 min readMar 22, 2021

Windows Terminal is a Microsoft open source project announced in May 2019. A first stable version was released in May 2020; I am guilty of overlooking it in these months as a Windows-based user, it really is a helpful tool with a high customizable interface.

Working for Accenture Google Business Group it is very common to have my day-by-day activities splitted in several GCP projects and also in different Google accounts for customers security restrictions.

Terminal offers an interesting feature: profiles.

Terminal will provide, out of the box, some dynamically generated profiles:

  • Cmd prompt
  • Windows Powershell
  • Azure Cloud Shell
  • Any WSL you have installed in your Windows

But it also let you define different profiles that you can launch directly from an easy access pick-list:

Final result

As you can see I am able to define several Google Cloud Shell profiles for several projects/accounts. I find this to be very handy, let’s see how to do it.

Requirements

Steps

Login to your account

Open WSL and login to your google account:

gcloud auth login {user_email}

Follow the link in the browser and provide the verification code to the prompt.

Define a switching script

Let’s define a shell script to switch account/project using script parameters and launch a ssh session towards Google Cloud Shell using Google Cloud SDK:

#!/bin/bash
gcloud auth login $1
gcloud config set project $2
gcloud cloud-shell ssh

Save it to ~ folder as set-gcloud-env.sh

Generate a guid

Open a Windows Powershell and use the command:

[guid]::NewGuid()

Save the result for next step.

Define Terminal profile

Open settings from the pick-list of Terminal, it will lead to a setting.json file, let’s add a new element with the required attributes into profiles.list section of the json object:

{"guid": "{{guid_generated}}","name": "{client} {project_name}","commandline": "wsl ~/set-gcloud-env.sh {user_email} {project_name}","hidden": false}

Save settings.json, you don’t need to restart Terminal.

Result

Click on the profile created in the last step from the pick-list:

Connected to the configured Cloud Shell profile :)

We successfully created a working Google Cloud Shell profile !

The first connection will prompt for a passphrase generating personal ssh keys and publishing the public key to the Google Cloud Shell, it will also modify your ~/.ssh/known_hosts .

Repeat the steps for any profile needed.

Customization

Terminal provide a lot of customizable fancy attributes such as:

  • icon
  • tabColor
  • acrylicOpacity

You can find documentation on customizable attributes here .

NB

As in browser sessions, Google Cloud will retain your provisioned machine if inactive for some time. In this case you will need to restart the profile using the pick-list in order to request a new session.

Ciao! 👋

AL

Ref

[1] Terminal documentation

[2] Terminal github project

[3] Profile attributes for Terminal

[4] gcloud cloud-shell ssh command

--

--