{"id":21974526,"url":"https://github.com/francescodisalesgithub/google-cloud-shell-hacking","last_synced_at":"2025-04-28T15:42:04.555Z","repository":{"id":159504217,"uuid":"561533420","full_name":"FrancescoDiSalesGithub/Google-cloud-shell-hacking","owner":"FrancescoDiSalesGithub","description":"Hacks for a better google cloud shell experience","archived":false,"fork":false,"pushed_at":"2024-10-15T20:36:22.000Z","size":648,"stargazers_count":32,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-30T10:51:13.413Z","etag":null,"topics":["api","cloud","cloud-shell","gcp","google","hacking","hacks","rest-api","secure-shell","shell","ssh","tricks"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FrancescoDiSalesGithub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-03T22:38:59.000Z","updated_at":"2025-03-28T14:38:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"36e983df-5d4b-46a8-9a7d-792d0fdcd51b","html_url":"https://github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrancescoDiSalesGithub%2FGoogle-cloud-shell-hacking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrancescoDiSalesGithub%2FGoogle-cloud-shell-hacking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrancescoDiSalesGithub%2FGoogle-cloud-shell-hacking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FrancescoDiSalesGithub%2FGoogle-cloud-shell-hacking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FrancescoDiSalesGithub","download_url":"https://codeload.github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251340704,"owners_count":21573964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","cloud","cloud-shell","gcp","google","hacking","hacks","rest-api","secure-shell","shell","ssh","tricks"],"created_at":"2024-11-29T15:46:02.305Z","updated_at":"2025-04-28T15:42:04.518Z","avatar_url":"https://github.com/FrancescoDiSalesGithub.png","language":"Shell","readme":"# Google-cloud-shell-hacking\nHacks for a better google cloud shell experience\n\n![alt text](https://github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking/blob/main/cludshell.jpeg)\n\n# Summary\n* Donation\n* Introduction\n* Do and don't\n* Cons of Google Cloud Shell\n* Hacks of Google Cloud Shell\n* SSH on the google cloud shell using the private key\n* Putting the public key on google cloud shell\n* Start the google cloud shell instance\n* Check the ip of the google cloud shell\n* Run the google cloud shell in ssh\n* Connect a google cloud shell to another google cloud shell\n* Getting oauth token on a running instance of a google cloud shell\n* Change location and zone of the google cloud shell\n* Use the google cloud shell as proxy\n* Running another operative system at the login in the google cloud shell\n* Using the postgres database\n* Autorun the Google Cloud shell at login\n* Containers stored locally in google cloud shell\n* Persistent postgresql data\n* Enabling systemctl on google cloud shell\n* Cockpit interface on google cloud shell\n* Connect external drives to google cloud shell\n* Connect with rdp protocol to Google cloud shell\n* Windows Server on google cloud shell\n* Removing bloat from google cloud shell\n* Using dbeaver on a google cloud shell database\n* Gitlab on google cloud shell\n* Scheduling on google cloud shell\n* Restarting the google cloud shell without using the gui\n* Putting the public key manually on a running google cloud shell instance\n* Alternative to ngrok (Poor man's ngrok)\n* Getting http hostname\n  \n# Donation\n\nBefore starting with this hacking guide, If you want to support me, or if this guide helped you, or you want to buy me a coffee, you can donate with paypal at the following url:\n\n```\nhttps://www.paypal.me/francescodisales\n```\nOr with monero at the following address:\n```\n4B9WQivaHfd3miDfPKEfCianocGpBx9d8FXycz2vmNW3aBDVKHgkBd9Gmapt4RBVEpTwnehujsiUBBehUiLvnEHs7VFstCC\n```\nor donate some bitcoins at the following wallet:\n```\nbc1qff3uyjz3zrtz6h6g8aydph70hhlcj9t3q2ynw4\n```\n\n\n# Introduction\n\nWhen you create a google account, you obtain a shell for google cloud. These are the features:\n\n* 5GB hard-drive\n* 8GB RAM\n* devops tools installed\n* git installed\n* Debian linux distribution\n\n# DO AND DON'T\n\nDo:\n* develop\n* trying other programs\n* trying google apis\n* using your cloud shell as proxy (google will still know about your data...)\n* having a personal vps\n\nDon't:\n* mining\n* unethical hacking\n\n# Cons of Google Cloud Shell\nGoogle cloud shell has the following problems:\n\n* The vm is ephimeral that means that after 1 Hour of inactivity all the content outside the $HOME folder will be lost\n* The google cloud shell is interactive so the crontab will not work\n* You have 50 hours available to use the google cloud shell, after Google will reset the time at a specific date.\n\n# Hacks of Google Cloud Shell\nHere there's the interesting part of this repository:\n\n* The google cloud shell has an hidden drive (sda1) which is 60GB you can mount it in the home folder but after the session is lost everything is lost\n* When you start for the first time the google cloud shell it could track your commands. Try the following command: `gcloud config set disable_usage_reporting true`\n\n# SSH on the google cloud shell using the private key\n\nWhen you start a cloud shell with the gcloud-cli or with cloud shell web page, it is assigned an ip to your google cloud shell and it seems that you can not ssh if not using the webpage or the gcloud-cli. The ssh shell listens on the port 6000 and in the sshd config the password authentication is disabled so it means that it is used the key authentication. Generate on your machine a keypair:\n\n`ssh-keygen -t rsa`\n\nthen get the oauth token from google:\n\n* go to https://developers.google.com/oauthplayground/\n* search for Cloud Shell api v1\n* after selecting, choose https://www.googleapis.com/auth/cloud-platform\n* Login and authorize the application\n* On step 2 ask for auth token\n* On step 3 copy the access token\n\nAfter doing these steps you need to call the following api:\n\n* https://content-cloudshell.googleapis.com/v1/users/me/environments/default:addPublicKey [POST] (will make you add your public key you created locally)\n* https://content-cloudshell.googleapis.com/v1/users/me/environments/default:start [POST] (will make you start the instance)\n* https://content-cloudshell.googleapis.com/v1/users/me/environments/default [GET] (will tell you the ip of the google cloud shell)\n\n## Putting the public key on google cloud shell\n\nThe api has a POST method. Run the api with the following body:\n```\n{\n  \"key\": \"ssh-rsa content of the public key\"\n}\n\nwhere content of the public key = abkjdksajkgajkdhkhksda  \nno username should be pasted after the rsa encryption\n\nExample:\n\n{\n  \"key\":\"afabasjdgnjadkjadhaksdsajkdsjakd\"\n}\n\n```\nAnd the header **Authorization**. It should has value Bearer value-of-the-access-token.\n\nThe content of the public key can be obtained by run the following line:\n`cat .ssh/id_rsa.pub`\n\n## Start the google cloud shell instance\n\nUse the following api:\nhttps://content-cloudshell.googleapis.com/v1/users/me/environments/default:start \n\nAdd the header **Authorization**. It should has value Bearer value-of-the-access-token. The json request is the following:\n```\n{\n  \"accessToken\": \"access-token-value\",\n  \"publicKeys\": [\n    \"content-of-the-local-public-key\"\n  ]\n}\n```\nThen run the api\n\n## Check the ip of the google cloud shell\n\nRun:\n```\n https://content-cloudshell.googleapis.com/v1/users/me/environments/default\n```\n\nLike the previous one it has the **Authorization header**. Run it and you will have the IP of your google cloud shell.\n\n## Run the google cloud shell in ssh\n\nRunning the api:\n```\nhttps://content-cloudshell.googleapis.com/v1/users/me/environments/default:start\n```\nAs response of the rest api, search for the json keys:\n\n* sshHost\n* sshPort\n\nyou can connect in ssh with the terminal by doing:\n\n```\nssh -i my_key_rsa -p value_of_sshPort my_google_username@value_of_sshHost\n```\n\nIf everything goes well you will have a ssh session with the google cloud shell without using the webpage or the gcloud-cli.\n\n\n# Connect a google cloud shell to another google cloud shell\n\nLet's suppose we have two users:\n* UserA\n* UserB\n\nUserA wants to connect to UserB's cloud shell.\n\nUserA has to retrieve the oauth token, and register on his google cloud shell the public key of UserB's cloud shell. Then download from UserB's cloud shell the private key of the UserB. Finally he can run the following command: `ssh -i userb_rsa -p 6000 UserB@IP-CLOUD_SHELL_USERB`\n\n# Getting oauth token on a running instance of a google cloud shell\n\nIf you want an oauth token while logged in your google cloud shell, you can run the following command:\n```\ngcloud auth application-default print-access-token\n```\n\n# Change location and zone of the google cloud shell\n\nIf you want that your google cloud shell starts to a different country, then you have to edit your torrc file adding something among this:\n\n```\nExitNodes {Country}\n\n```\n\nWhere Country can be found at the following link:\n\n```\nhttps://www.iso.org/obp/ui/#search\n```\n\nthe value Country you have to put in the torrc file is the Alpha2-code value in the link above. Remember to use a country that is not too far from your position otherwise you will have a connection timeout. after putting the line:\n\n```\nExitNodes {Country}\n\n```\nsave the torrc file and restart the tor service if you have it running:\n\n```\n\nsudo service tor restart\n\n```\n\notherwise just start the tor service:\n\n```\n\nsudo service tor start\n\n```\n\nto run the google cloud shell you have three choices:\n\n* running with gcloud-cli using proxychains =\u003e ` proxychains gcloud cloud-shell ssh --authorize-session`\n* using postman and setting in postman the tor proxy\n* accessing to the google cloud shell webpage with your web browser (remember to set the proxy to http proxy =\u003e socks =\u003e localhost and port 9050)\n\n\n# Use the google cloud shell as proxy\n\nIf you want to use your google cloud shell instance as proxy you need to run the following commands (or insert them in the .bashrc file):\n\n```\nsudo apt install -y squid\n```\nJust for let you know Squid is a http proxy server. Create a **squid.conf** file with the following settings:\n\n```\nhttp_port 3128\ncache_dir /var/cache/squid 100 16 256\nacl all src 0.0.0.0/0\nhttp_access allow all\n\n```\n\ncopy the **squid.conf** file to **/etc/squid**\n```\nsudo cp squid.conf /etc/squid\n```\n\nFinally run the squid service:\n\n```\nsudo service squid start\n```\n\nUse ngrok to let the proxy be available from outside:\n```\n./ngrok tcp 3128\n```\nAfter running copy the tcp:// url. If you want to run the proxy from a browser it is suggested to remove the tcp:// part and the port and put the port in the port field of your browser proxy settings (squid is a http proxy server).\n\nFor better use at startup the .bashrc file should have the following lines:\n\n```\n\nsudo apt install -y squid\nsudo cp squid.conf /etc/squid/\nsudo service squid start\ncd ngrok;./ngrok tcp 3128\n\n```\n\n# Running another operative system at the login in the google cloud shell\n\nIf you want to run another operative system instead of debian, you can try to create an operative system container. Create in your home folder a path like:\n```\n/home/your_google_account_name/your_favourite_operative_system\n```\nIn the **your_favourite_operative_system** folder create a root folder:\n```\nmkdir root\n```\nAlways in this directory (/home/your_google_account_name/your_favourite_operative_system), create a docker-compose.yml with the following informations:\n```\nversion: '3.6'\nservices:\n  kali:\n    image: \"ubuntu\" # you can try other operative system such as alpine kali arch and so on\n    tty: true\n    stdin_open: true\n    command: bash # if alpine or unknown operative system use sh\n    volumes:\n      - \"/home/your_google_account_name/your_favourite_operative_system/root:/root\"\n```\nBefore editing the **.bashrc** file, run:\n```\ndocker-compose up -d\n```\nthen check the name of the container:\n```\ndocker ps -a\n```\nAt the column NAME save somewhere the name of the container. After this check, go to your home folder and edit the **.bashrc** file appending the following line of code:\n\n```\ncd /home/your_google_account_name/your_favourite_operative_system; docker-compose up -d \u0026\u0026 docker start -i your_container_name\n```\n\nWait for the current google cloud shell to end and start a new one. On boot, you will have a running instance of your favourite system, but you will lose all your installed apps on the container.\n\n\n# Using the postgres database\n\nIn the cloud shell run these commands:\n\n```\nsudo service postgresql start \nsudo su\nsu postgres\npsql\n\n```\n\nAt the first command you start the postgresql database service, and then you need to be the postgresql user so you use the su command and finally launching psql you have the interactive shell for postgresql. \n\n# Autorun the Google Cloud shell at login\n\nIn the Google Cloud shell session edit in your home folder the .bashrc file. At the end of the file write the commands you want to run at login, then save and close the files. At a new login the cloud shell will run the commands you have written in the .bashrc file.\n\n# Containers stored locally in google cloud shell \n\nIf you're using the docker you will see that, after the session is over you will lose all the content in your containers. There are two possible solutions:\n\n* using volumes\n* export and import of the container\n\nIn this paragraph we will discuss about how to export and import a container. Start with pulling a container such as ubuntu:\n`docker pull ubuntu`\n\nRun the container by doing:\n`docker run --name=ubuntu -i -t ubuntu /bin/bash`\n\nexit from the shell container, and run the following command:\n`docker export -o ubuntu_container.tar`\n\nthis command will create a tar archive with all the content in the container. Doing that remove the ubuntu image:\n`docker rmi ubuntu'\n\nNow load your container instance:\n`docker import ubuntu_container.tar ubuntu_mycontainer:latest`\n\nIn the import command is important to pass as argument:\n* the tar archive where all the informations of the container is stored\n* the name to give to the imported container and the tag (usually should be latest)\n\nTo check if the container has been imported, run again **docker images**, it should have the new name you gave to the imported container.\nRun your new container by doing:\n`docker run --name=mypersonalcontainer -i -t ubuntu_mycontainer:latest /bin/bash`\n\nThis command would run your container with the informations you have inside it\n\n\n## Persistent postgresql data\nIf you want to persist your data in your google cloud shell, you need to do the following:\n* create a directory in your home folder\n* `mv /var/lib/postgres/15/main /home/your_google_account/database/` \n* edit the following file **/etc/postgresql/15/main/postgresql.conf** and at the voice **data-directory** add the path **/home/your_google_account/database/**\n* start the postgresql service with `sudo service postgres start` if everything is ok postgresql will be up and running\n\nWhen a new instance of the google cloud is running, you only need to edit the file **/etc/postgresql/15/main/postgresql.conf** and edit the **data-directory** voice\n\n## Enabling systemctl on google cloud shell\nSince the instance of the google cloud shell works on a docker container, systemctl is not enabled. It is suggested to build a docker image as follow:\n```\nfrom ubuntu\n\nrun apt update \u0026\u0026 apt install -y systemd systemd-sysv sudo\nrun useradd -ms /bin/bash myuser\nrun echo 'myuser:password' | chpasswd \nrun usermod -aG sudo myuser\n \ncmd [\"/lib/systemd/systemd\"]\n\n```\n\nafter saving the dockerfile run the following command:\n`docker build -t mysubsystem .`\n\nwait for the complete build.\n\nAfter the build has done, run the docker run command:\n`docker run --privileged --name=mysubsystem-container -i -t mysubsystem`\n\nDocker will run the container, and it will present you the ubuntu login screen. At the login credentials enter the credentials you wrote in the dockerfile and then you will have a linux container with systemctl enabled. If you want to exit from the container run the **shutdown** command:\n`sudo shutdown now`\n\n## Cockpit interface on google cloud shell\n\nif you want to manage the google cloud shell through cockpit as prerequisite you need to read the previous paragrah about how to install systemctl on google cloud shell. When you have installed the container in which there is systemctl run this procedure:\n\n```\n\nsudo apt update\nsudo apt install -y cockpit wget\n\nmkdir ngrok\ncd ngrok\n\nsudo systemctl start cockpit\n\nwget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz\ntar -xzvf ngrok-v3-stable-linux-amd64.tgz\nrm ngrok-v3-stable-linux-amd64.tgz\n\n```\n\nthen go to your ngrok account and copy your authentication token. You can find it in the ngrok account page at the voice **getting started -\u003e setup and installation**. In that page you can find an instruction like the following:\n\n`ngrok config add-authtoken` \n\nand there will be near this instruction your authentication token. Paste all the instruction into the terminal where the google cloud shell is running like this:\n\n`./ngrok config add-authtoken YOUR_AUTH_TOKEN`\n\nNow you only need to run ngrok:\n\n`./ngrok tcp 9090`\n\nThere should be an url like the following: **tcp://0.tcp.eu.ngrok.io:10230**, please copy the address after tcp:// and paste in your browser. As you reach the webpage, enter as credentials the credentials in your linux container.\n\n## Connect external drives to google cloud shell\n\nIf you want to add your drives to the google cloudshell you need the following requirements:\n\n* sshfs\n* ngrok\n* (optional) if you have other mass storage such as microsd or hard-drives use a hdd docking station\n\nfirst on your system install openssh-server if you don't have it:\n`sudo apt intall openssh-server -y`\n\nAfter the installation on your local machine run the ssh service:\n`sudo service ssh start`\n\nThen with ngrok listen on port 22:\n`./ngrok tcp 22`\n\nOn your google cloud shell install sshfs:\n`sudo apt install -y sshfs`\n\nAfter installing it, always in your google cloud shell run the following command line command:\n`sshfs -p NGROK_PORT USER@NGROK_TCP_ADDRESS:LOCAL_PATH PATH_GOOGLE_CLOUD_SHELL`\n\nwhere:\n* NGROK_PORT is the port ngrok gives on your local machine\n* USER is your user in your local machine\n* NGROK_TCP_ADDRESS is the address that ngrok gives you\n* LOCAL_PATH is the path where you have locally your mass storage device\n* PATH_GOOGLE_CLOUD_SHELL is the path where do you want that your local storage device must be mount on the google cloud shell\n\nAfter that if you are already in the folder where the device has to be mount, go back one directory and then go back to your mount folder. When you are done you can unmount the device on your google cloud shell by doing the following:\n\n`umount PATH_GOOGLE_CLOUD_SHELL`\n\nRemember that PATH_GOOGLE_CLOUD_SHELL is the path where do you want that your local storage device must be mount on the google cloud shell.\n\n## Connecting using rdp on Google cloud shell\n\nIf you have windows remote desktop and you want to connect to the Google cloud shell, you have to do the following steps:\n* Run `sudo apt install -y xrdp dbus-x11 xfce4 xfce4-goodies`\n* Start xrdp service: `sudo service xrdp start`\n* Create and user and give him a password: `adduser dev`\n* Assign the user to the sudo group: `usermod -aG sudo dev`\n* Start ngork: `ngrok tcp 3389`\n* Copy the address and port after the tcp://\n* Open the remote desktop app for windows and connect\n* Login with the user created at the third point and you have your Google cloud shell environment on rdp\n\n## Windows Server on Google\n\nAs prerequisite you have to add in your google drive a qcow image of your windows server, also you have to follow the steps of the previous paragraph.\nThen you have to install qemu:\n\n`sudo apt install -y qemu-system-x86`\n\nAfter that install firefox:\n\n`sudo apt install firefox-esr`\n\nOn firefox, change the download location to **/root** and then go to **google.com** and log in as your google user, then, go to your google drive and download the qcow image of windows server. After downloading go to /root and type the following command:\n\n`qemu-system-x86_64 -img windowserver.qcow -m 4096 -boot c`\n\n## Removing bloat from google cloud shell\n\nIf you want to remove bloating software from your google cloud shell download the file in this repository called **remove-bloat.sh**. If you want to have always free space on your google cloud instance, write the **bash.rc** file in your google cloud home folder and write:\n`chmod +x remove-bloat.sh; ./remove-bloat.sh`\n\nAt the next google cloud startup instance it would took some minutes until the removing procedure is done.\n\n## Using dbeaver on a google cloud shell server\n\nIf you want to connect with dbeaver with the postgres database you need to do the follow:\n\n* start the postgres service\n* let ngrok listen to the port 5432 by running it as a tcp connection: `ngrok tcp 5432`\n* copy the url and port and past it somewhere\n* open a new instance of google cloud shell with the tmux and elevate privileges as root by doing sudo su and then go as postgres user by doing su postgres\n* connect to the database doing psql -u postgres\n* connect to the default postgres database by doing \\c\n* change the default credentials of postgres by doing: `alter user postgres password mysupersecurepassword`\n* open dbeaver and create a postgresql connection\n* as the voice host choose the ngrok hostname (something like 0.tcp.eu.ngrok.io) and the relative port\n* insert the credentials you have edit before with the alter user command\n* test the connection. If everything goes well a message box will alert that the connection works\n\n## Gitlab on google cloud shell\n\nTo install Gitlab on google cloud shell you first need to edit your .bashrc file appending the following lines:\n\n```\nexport GITLAB_HOME =/home/your_google_account_username/your_gitlab_folder\ncd /home/your_google_account_username/your_gitlab_folder; docker-compose --force-recreate up -d\n/home/your_google_account_username/ngrok/./ngrok http 80\n\n```\n\nAfter editing the file .bashrc, go to the your_gitlab_folder folder and make the following folders:\n\n* config\n* logs\n* data\n\nin this your_gitlab_folder folder, create a docker-compose.yml file and add these lines:\n\n```\nversion: '3.6'\nservices:\n  web:\n    image: 'gitlab/gitlab-ce:latest'\n    restart: always\n    hostname: 'localhost'\n    ports:\n      - '80:80'\n      - '443:443'\n    volumes:\n      - '$GITLAB_HOME/config:/etc/gitlab'\n      - '$GITLAB_HOME/logs:/var/log/gitlab'\n      - '$GITLAB_HOME/data:/var/opt/gitlab'\n    shm_size: '256m'\n\n```\n\nSave the file. Exit from the google cloud shell instance and start a new one. When a new google cloud shell sessions starts a gitlab docker instance will start. It may take 4 to 7 minutes for the container to boot. When done copy and paste the ngrok http link to visit the web interface of your gitlab instance.\n\nNOTE: at first installation on gitlab it may be required to insert a root password. To find it first run `docker ps -a` and search the name of the container. Then run: `docker exec name_of_the_container cat /etc/gitlab/initial_root_password` after the output of the cat command paste in the web login interface and log in.\n\n## Scheduling on google cloud shell\n\nSince scheduling is not enabled on google cloud shell, it is possible to use a java program to do that. First write/copy the following code in a file called **TimerScheduler.java** :\n\n```\n\nimport java.util.Timer;\nimport java.util.TimerTask;\n\npublic class TimerScheduler {\n\n    public static void main(String[] args) {\n        Timer timer = new Timer();\n\n        // Schedule a task to run every 1 second\n        timer.scheduleAtFixedRate(new TimerTask() {\n            @Override\n            public void run() {\n                System.out.println(\"Hello, World!\");\n            }\n        }, 0, 1000);\n\n        // Allow the scheduler to run for 10 seconds\n        try {\n            Thread.sleep(10000);\n        } catch (InterruptedException e) {\n            e.printStackTrace();\n        }\n\n        // Cancel the timer\n        timer.cancel();\n    }\n}\n\n```\n\nThen to compile it run:\n\n```\n\njavac TimerScheduler.java\n\n```\n\nto run it type:\n\n```\n\njava TimerScheduler\n\n```\n\nit will run the java program but print at output **Hello world!**. For a different logic, you have to develop in java your scheduling job logic, for example:\n\n* checking an ip\n* run a program each n seconds\n* download a script\n\nAnd so on.\n\n## Restarting the google cloud shell without using the gui\n\nIf you have to restart the google cloud shell due to misconfigurations or server problems, you can restart the google cloud shell instance by enabling the password authentication to the ssh deamon. Edit the sshd config file:\n\n```\n\nsudo vim /etc/ssh/sshd_config\n\n```\n\nsearch for **PasswordAuthentication** and replace no with yes then save and quit with vim. Then create a user in linux and after the creation connect locally to your google cloud shell instance:\n\n```\n\nssh myuser@localhost\n\n```\n\nInsert the password, and then exit from the ssh session. The google cloud shell will restart by itself.\n\n\n## Putting the public key manually on a running google cloud shell instance\n\nIf you have a running instance of a google cloud shell, and you want to connect in ssh with your terminal, follow these steps:\n\n* Create a ssh keypair:\n\n```\n\nssh-keygen -t rsa\n\n```\n* Copy the content of the public key (usually id_rsa.pub) the content to the authorized_key file and after reopen the authorized_keys files and remove the host near your public key hash:\n\n```\n\nsudo cat id_rsa.pub \u003e\u003e /home/yourgoogleaccount/.ssh/authorized_keys\nsudo cat id_rsa.pub \u003e\u003e /etc/ssh/keys/authorized_keys\n\n```\n\n```\nContent of the authorized_keys file at the bottom:\n\nssh-rsa 1asdafnkjnkfas...\u003cSNIP\u003e...a google-ic2-shell #google-ic2-shell has to be removed\n\n```\n\n\n\n\n* Restart the ssh service:\n\n```\n\nsudo service ssh restart\n\n```\n\n* Search for the google cloud shell public ip:\n\n```\ncurl ifconfig.me\n\n```\n\n* Copy the content of the private key to your local computer and connect to the google cloud shell ssh server:\n\n```\n\nssh -i id_rsa -p 6000 yourgoogleaccount@ip-google-cloud-shell\n\n```\n\n## Alternative to ngrok (Poor man's ngrok)\n\nSince the new version of ngrok with the free tier has a traffic of 1 GB in and out, you can recreate ngrok's functionality using ssh port forwarding.\n\n* Create a vps on linode (Suggested the following one: Shared CPU, 512 MB ram) near your google cloud shell instance so that the network traffic is not slow\n* Connect to the vps\n* Go to /etc/ssh/sshd_config:\n\n  ```\n  sudo vim /etc/ssh/sshd_config\n  \n  ``` \n* Uncomment the voice **GatewayPorts** and set it to yes\n* Restart the ssh service on the vps\n  \n  ```\n\n  sudo service ssh restart\n\n  ```\n* Go to your google cloud shell instance and run the following command:\n  ```\n\n  ssh -R \u003cremote_port\u003e:localhost:\u003cport_where_the_program_is_listening_on_the_google_cloud_shell\u003e root@ip-vps\n\n  ```\n* Connect to the vps with the assigned remote port\n\nFor Clarification the remote port is the port in which the vps listen to the traffic generated in outbound by the google cloud shell\n\n\n# Getting http hostname\nIf you want to host on the google cloud server a http server or a web application that listens on a specific port, and you want to use the hostname with a NS dns record you have to follow the following steps:\n* Start your google cloud shell\n* Press on the button web preview\n* Preview on port 8080\n* the browser should redirect to an url like:\n  ```\n  https://8080-cs-12345678-default.cs-europe-west1-iuzs.cloudshell.dev/?authuser=0\u0026redirectedPreviously=true\n\n  ```\n* Now run an http application on a port different than 8080\n* From the URL :\n```\nhttps://8080-cs-12345678-default.cs-europe-west1-iuzs.cloudshell.dev/?authuser=0\u0026redirectedPreviously=true\n```\nReplace 8080 with the number of the port where the web application is listening\n* now you should be enable to see your web applicaton\n\n## Extra\nFrom the url that the google cloud shell gave you, you can assign with cloudflare an address dns record type.\n\n","funding_links":["https://www.paypal.me/francescodisales"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrancescodisalesgithub%2Fgoogle-cloud-shell-hacking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrancescodisalesgithub%2Fgoogle-cloud-shell-hacking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrancescodisalesgithub%2Fgoogle-cloud-shell-hacking/lists"}