Why google cloud shell auto disconnect after 1 hours - restart

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!

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.

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

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.

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.

Related

GCloud auth login: Ports 8085 and 8184 possible blocked

I have installed and uninstalled and reinstalled GCloud on MACOS Monterey (Chipset M1) and I'm facing the next situation: When I run in Terminal gcloud auth login, it displays the next message:
WARNING: Failed to start a local webserver listening on any port between 8085 and 8184. Please check your firewall settings or locally running programs that may be blocking or using those ports.
WARNING: Defaulting to --no-browser mode.
You are authorizing gcloud CLI without access to a web browser. Please run the following command on a machine with a web browser and copy its output back here. Make sure the installed gcloud version is 372.0.0 or newer.
I have tried in many ways to install: The last one was this:
curl https://sdk.cloud.google.com | bash
exec -l $SHELL #restart shell
But I still facing that message.
Anybody couls help me with this?
This happens because my Internet provider has blocked these ports. There will be to make some fixes to the router.
Patch solution for this:
gcloud auth login --no-launch-browser
Follow the instructions given on Terminal

Disable install of VS Code server

I use my VS Code remote - SSH extension to jump between a lot my customers servers, and would actually like not install the VS Code server on every server that I use.
Is there a way not to install the VS Code server, when you use the Remote - SSH extension, or is there maybe even another extension I should use instead?
To fix this on your own (without using the script mentioned above), you could simply log into each of the linux. cs servers (using SSH), then the command pkill -u node , which will stop any running vscode-server processes
I fixed it but not using the official remote - SSH, but the extension SSH FS, which is a little more combersome as it can see you'r "normal" ssh config, but i works.
https://marketplace.visualstudio.com/items?itemName=Kelvin.vscode-sshfs

How to connect to GCP Cloud SQL using CLoud IAM user

The first answer here is a guide on how to connect to your Cloud SQL database using a Cloud SQL IAM User.
Follow these steps to create a user first.
Install Google Cloud SDK for your local machine.
https://cloud.google.com/sdk/docs/install
Run gcloud in any terminal to authenticate your Google Cloud Platform User on your system.
gcloud init
Download Google Cloud SQL Auth Proxy for your operating system. https://cloud.google.com/sql/docs/postgres/sql-proxy
Windows: Just Download
MacOS: curl -o cloud_sql_proxy https://dl.google.com/cloudsql/cloud_sql_proxy.darwin.amd64
MacOS: chmod +x cloud_sql_proxy
Run the proxy from the downloaded directory to start. Keep it running for the duration you want to be connected. Choose a TCP port that is unused on your system. the -instances field is your instance connection name, on the instance overview page
Windows: .\cloud_sql_proxy.exe -instances="project:region:db-instance"=tcp:5432 -enable_iam_login
MacOS Silicon: softwareupdate --install-rosetta - needed to run software for older cpus
MacOS Silicon: arch -x86_64 zsh - opens up a terminal which can run the software
MacOS & MacOS Silicon: ./cloud_sql_proxy -instances="project:region:db-instance"=tcp:5432 -enable_iam_login
The service is now running and allows connection to the database. This includes any coded packages and modules from your favourite language, also applications like PgAdmin, DataGrip, Jetbrains Database Navigator and Chrome Database explorers to connect. Set connection settings to
Host: localhost or 127.0.0.1
User: username#email.com
Pasword: yourGCPpassword
Other Resources
Quickstart for using the Cloud SQL Auth proxy
MacOS running arch64 processes
Debugging Connection Issues

Google cloud_sql_proxy keep my connection alive

I'm making a connection between a Google Compute Engine instance and a Google Cloud SQL instance, using the Cloud SQL Proxy.
Using this tutorial, I have managed to establish a connection by running this command:
./cloud_sql_proxy -instances=<INSTANCE_CONNECTION_NAME>=tcp:3306
However, when I quit the terminal instance I used to enter the above command the connection is lost.
How can i keep the connection alive throughout?
If you want the process of cloud_sql_proxy to run as long as the Google Compute Engine (GCE) instance is running, just make the process run in the background.
For that you just add the '&' character in the end of your command, so i would go like this:
./cloud_sql_proxy -instances=<INSTANCE_CONNECTION_NAME>=tcp:3306&
This way, as along as you don't stop the GCE instance, you can ssh to it and connect to your Cloud SQL instance (with INSTANCE_CONNECTION_NAME) with the Cloud SQL Proxy being used.

ssh not working for Amazon EC2 server

I have setup and launched an instance of Amazon EC2 server with Ubuntu in it. Now I have integrated cygwin with command prompt also so all linux commands are working in command prompt.
I tried to access the server using ssh -i munish.pem ubuntu#52.11.190.155 (munish.pem contains my secret key).
After running this command I get an error: 'ssh' is not recognized as an internal or external command, operable program or batch file. I searched net and could find solution for github not for Amazon EC2 service...
You can use putty software in window for connecting to the AWS EC2 instance.
Follow the below steps:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html
Hope it helps..
You can open PowerShell and check ssh command is available or not.
If not, you can install OpenSSH in Windows 10. See following guide on how to install it.
https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse