Introduction
VertexAI is the suite of AI or machine learning tools provided by Google Cloud. Workbench is Google Cloud's managed JupyterLab service, backed by Google Cloud Compute Engine.
This article explains how to connect to your Workbench instance and even use it with VS Code Remote - SSH.
One benefit of developing via VS Code SSH is that VS Code can inject your Git credentials into the terminal, which can make collaborating smoother.
HOWTO
Start by creating a new SSH key pair
ssh-keygen -f ~/.ssh/google_compute_engine
If you are on Windows using PowerShell, you can't use the tilde and have to do
ssh-keygen -f "$env:USERPROFILE/.ssh/google_compute_engine"
Next, enrol your public key with the following command
gcloud compute os-login ssh-keys add --key-file "~/.ssh/google_compute_engine.pub"
It will show you the username associated with the key file. For me, it was my email address with . and @ replaced with underscores. Remember this for later.
Next, you can run the following, which will write an entry to the local SSH config for each instance that is running (I think).
gcloud compute config-ssh
This will write entries to ~/.ssh/config.
Instance IPs are not persistent, so if you restart the instance, you will need to edit the ~/.ssh/config file to substitute the new IP.
The command output will also give you an example command to run with the instance alias. Like so:
# doesn't work
ssh <instance-name>.<zone>.<project>
However, this will not work without a username. You can add it to the command:
ssh <username>@<instance-name>.<zone>.<project>
Or you can add a line to the ~/.ssh/config file. Find the block for the instance and add a line
User <username>
Don't forget to indent with 2 spaces.
Connecting to the jupyter user on VS Code
You can only use the method described to log into an account named after your email. In order to access the Jupyter goodies, you need to use the user called jupyter.
When you are in an SSH command line, you can just run sudo su jupyter and it will give you a shell for jupyter.
If you are using Remote - SSH on VS Code, however, you need VS Code to be running as jupyter.
Add the following lines to your settings.json
"remote.SSH.useLocalServer": true,
"remote.SSH.enableRemoteCommand": true,
Then add a RemoteCommand entry to ~/.ssh/config in the relevant host.
RemoteCommand sudo su jupyter
You may also need to add the following so that the sudo su command works.
RequestTTY force
If you have already connected to the host using VS Code, you will need to delete the entry in remote.SSH.remotePlatform corresponding to the host so that it does the first-time setup again.