Install VSCode - https://code.visualstudio.com/download Install Remote-SSH plugin inside VSCode from the extensions page
-
If you have the GCP SDK installed on your local machine
-
Run the following
gcloud compute config-ssh
Record the hostname it provides as an the SSH example.
E.g.$ ssh jumpbox.us-central1-a.pal4pe-1109-mproud
-
In VSCode open
Remote-SSH: Open Configuration File
from the command paleteEdit your ssh config and add the ubuntu user to the end of the section for you jumpbox
E.g.
Host jumpbox.us-central1-a.abcdefg HostName 1.2.3.4 IdentityFile /home/matt/.ssh/google_compute_engine UserKnownHostsFile=/home/matt/.ssh/google_compute_known_hosts HostKeyAlias=compute.123456789123456798 IdentitiesOnly=yes CheckHostIP=no User ubuntu
-
-
If you connected via the GCP cloud shell
-
Make a connection to your jumpbox then end the connection
If it asks you to use a region say no.
gcloud compute ssh ubuntu@jumpbox No zone specified. Using zone [us-central1-a] for instance: [jumpbox]. .... ubuntu@jumpbox:~$ logout Connection to 1.2.3.4 closed
Record the IP address. 1.2.3.4 will be used as an example
-
Run the following on the cloud shell machine
cat ~/.ssh/google_compute_engine
Get the contents in your clipboard -
On your local machine create the same file in your ssh directory
vim ~/.ssh/google_compute_engine
Paste in the contents of your clipboard -
Set the permissions on the file to be 600
chmod 600 ~/.ssh/google_compute_engine
-
Test the key works by sshing into your machine, using the IP address from step 1.
ssh -i ~/.ssh/google_compute_engine [email protected]
-
Open
Remote-SSH: Open Configuration File
from the command palete Set the contents to be the following, using the IP address from step 1.Host jumpbox HostName 1.2.3.4 IdentityFile ~/.ssh/google_compute_engine User ubuntu Port 22
-
-
Open
Remote-SSH: Connect To Host
in the command palette
Select the machine which matchs your ssh config file.
-
Ensure OpenSSH is installed
https://docs.microsoft.com/en-gb/windows-server/administration/openssh/openssh_install_firstuse -
To generate an SSH key pair open powershell and run.
mkdir $HOME/.ssh # OK if it already exists and generates an error ssh-keygen -b 2048 -t rsa -f $HOME\.ssh\jumpbox-pal -q -N """" cat $HOME\.ssh\jumpbox-pal.pub
-
Connect to the jump box
gcloud compute ssh ubuntu@jumpbox
-
Add the contents of your clipboard to the end of your authorized_keys file
vim ~/.ssh/authorized_keys
-
End connection to the jump box and record IP address. 1.2.3.4 will be used as an example
ubuntu@jumpbox:~$ logout Connection to 1.2.3.4 closed
-
Test the connection by trying to SSH into the jump box.
C:\Windows\System32\OpenSSH\ssh.exe -i $HOME\.ssh\jumpbox-pal [email protected]
-
In VSCode open
Remote-SSH: Open Configuration File
from the command paleteAdd the following to the end, updating the IP address recorded in the previous step.
Host jump_box HostName 1.2.3.4 IdentityFile ~/.ssh/jumpbox-pal User ubuntu Port 22
-
(Windows only) Open
Remote-SSH: Settings
from the command paletteFor the setting
Remote.SSH: Path
set:
C:\Windows\System32\OpenSSH\ssh.exe
-
Open
Remote-SSH: Connect To Host
from the command paletteSelect jump_box from the list
Select OS type to be Linux
Exactly what I needed!