5

I use Google Cloud Shell to run Jupyter Notebook on instance , but after 1 hours,the connection is disconnect.

And I reconnect to instance, there is nothing, is same as reset instance.

So, please tell me how to set up ,make the connection of cloud shell keep connect.

Thanks!

R. García
  • 815
  • 9
  • 20
hiyoung liu
  • 53
  • 1
  • 3

4 Answers4

5

Google Cloud Shell auto disconnect because you didn't do anything in the Cloudshell's terminal! So to keep the cloudshell session alive, you can enter the following javascript code to the browser's javascript console

setInterval(function() {document.elementFromPoint(500, 500).click();}, 30000);

That's the trick!

P/S: If you want to use Jupyter Notebook, why you don't use Google Colab instead? It has a pre-installed Jupyter Notebook as well as more CPU and ram. You can use the same js for Colab!

UPDATE: you can try Cloud Shell SDK, then connect to Google Cloud Shell by gcloud cloud-shell ssh, which is much faster than the web interface, allow port forwarding (based on ssh), and have a longer time limit.

You can even connect to it using VSCode.

raspiduino
  • 601
  • 7
  • 16
1

The virtual machine instance that backs your Cloud Shell session is not permanently allocated to a Cloud Shell session and terminates if the session is inactive for an hour.

https://cloud.google.com/shell/docs/limitations

Gaterde
  • 779
  • 1
  • 7
  • 25
  • Thanks!,I understand , If i keep use interactive ,Can it extend time? Or is there any other way to keep connection? Thanks – hiyoung liu Apr 23 '18 at 08:48
0

I am late to answer this but try this if not already. Open the sysctl.conf and add below lines.

grep keep /etc/sysctl.conf  
sudo vi /etc/sysctl.conf

net.ipv4.tcp_keepalive_time=60  
net.ipv4.tcp_keepalive_intvl=60  
net.ipv4.tcp_keepalive_probes=5  

stop and start your instance.

ram4189
  • 21
  • 4
0

Answer from a year later

You can use gcloud cli. Just install it, open a terminal and run gcloud cloud-shell ssh --authorize-session, then you can use the terminal.

You can also ssh from VSCode to Google Cloud Shell. Just set the key file to .ssh/google_compute_engine, get the ip of CloudShell machine by curl -L ipconfig.me, and then ssh to that ip with port 6000.

raspiduino
  • 601
  • 7
  • 16