Accessing Cloud Shell from the command line

If you have Google Cloud SDK installed, you can interact with Cloud Shell directly 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 the comfort of your local desktop.

Using 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 beta 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 beta 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 beta cloud-shell ssh
  2. Copy a file, 'data.txt', from Cloud Shell to your local machine:

    gcloud beta 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 beta cloud-shell get-mount-command ~/my-cloud-shell