38

Is it possible to connect to the Google Cloud Shell instance via the ssh? Maybe somehow with gcloud? So I can use it with my favorite terminal (iTerm in particular) and not with the Web-based shell.

Answer: yes it is now been possible: https://cloud.google.com/blog/products/gcp/introducing-the-ability-to-connect-to-cloud-shell-from-any-terminal

  • 3
    I don't think so - the point is not to use it for long term use - from this page: https://cloud.google.com/shell/docs/features - `When you start Cloud Shell, it provisions an f1-micro Google Compute Engine virtual machine running a Debian-based Linux operating system. Cloud Shell instances are provisioned on a per-user, per-session basis. The instance persists while your Cloud Shell session is active and terminates after an hour of inactivity.` – Morrison Chang Dec 25 '16 at 21:52
  • 1
    see my answer it's possible now –  Mar 27 '18 at 14:25
  • Can you revise the accepted answer. –  May 16 '18 at 11:45
  • 1
    answer has been plagiarized verbatim from here: https://cloud.google.com/blog/products/gcp/introducing-the-ability-to-connect-to-cloud-shell-from-any-terminal – Jean-François Fabre Aug 12 '19 at 09:29

3 Answers3

19

Yes. From the gcloud CLI, run gcloud cloud-shell ssh. This will establish an interactive SSH session with Cloud Shell.

Reference:

Travis Webb
  • 14,688
  • 7
  • 55
  • 109
  • 3
    For future readers, the CLI Cloud Shell Alpha version only works on Linux. For Windows (and Linux) I wrote a program that integrates your desktop with Cloud Shell and provides a lot of features. Source code is here: https://github.com/jhanley-com/google-cloud-shell-cli-go – John Hanley Oct 27 '19 at 16:48
  • Hm, i get a message: Access granted. Press Return to begin session. What if I do not need an interactive but an automated session? – Stiefel Nov 16 '22 at 16:23
  • 1
    It works for Windows as well. – FractalSpace Jan 15 '23 at 04:38
1

Yes, you can do that with 3 simple steps:

  1. open a terminal in your local system
  2. install google-cloud-sdk : sudo snap install google-cloud-sdk --classic
  3. Authenticate google-cloud-sdk with your google account : gcloud auth login NOTE : After running this command , your default browser will be open and will ask you to authenticate
  4. After the autherization, go back to the terminal and run the following commad to get access into the shell : gcloud cloud-shell ssh NOTE : If you are doing this first time, it may walk you through creating ssh keys, if it's happen, in my case, i continue with empty password
  5. So, whenever you need that cloud shell , just run : gcloud cloud-shell ssh
41bin
  • 11
  • 1
0

You can connect to a vpn from the cloud shell, put the needed binary in your home directory and write the necessary startup scripts (connect to vpn and start daemon etc) on top of the .bashrc file so that it get executed when you start the shell from your browser.

I also suggest to use mosh becasue routing this way is pretty terrible and maybe run ssh cipherless since the vpn is already encrypted.

You could also cobble the heartbeat to keep the shell alive but that's probably too much in abuseland, having a pinned tab for the cloud shell seems good enough to me.

untore
  • 603
  • 8
  • 16