Use Cloud Shell with the gcloud CLI

If you have the gcloud CLI installed, you can interact with Cloud Shell from your terminal and use it as a sandbox and a portable development environment. This provides the convenience of working with Cloud Shell resources, whether to quickly test an operation or use an IDE of your choice to edit a file saved on your Cloud Shell instance from your local desktop.

Use gcloud cloud-shell

The current gcloud cloud-shell command group offering provides the following functionality:

  • Establishing an interactive SSH session with Cloud Shell using gcloud cloud-shell ssh.
  • Copy files between your local and Cloud Shell machine via scp.
  • Mount your Cloud Shell directory to your local file system via sshfs.

For more detail, see the reference documentation for gcloud cloud-shell.

Example workflow

To illustrate the workings of gcloud cloud-shell, here is an example of how you can use these commands in practice:

  1. Start a SSH session:

    gcloud cloud-shell ssh
  2. Copy a file, data.txt, from Cloud Shell to your local machine:

    gcloud cloud-shell scp cloudshell:~/data.txt localhost:~data.txt
  3. If you're using Mac or Linux, you can mount your Cloud Shell home directory onto your local file system after installing sshfs.

    This allows you to edit the files in your Cloud Shell home directory using your choice of local tools. All the data in your remotely mounted file system is stored on a Persistent Disk and stored across sessions.

    gcloud cloud-shell get-mount-command ~/my-cloud-shell