Skip to content

Instantly share code, notes, and snippets.

@mollymerp
Last active January 10, 2024 14:52
Show Gist options
  • Save mollymerp/26ef43f8f72577e7133c95f9c9f893c8 to your computer and use it in GitHub Desktop.
Save mollymerp/26ef43f8f72577e7133c95f9c9f893c8 to your computer and use it in GitHub Desktop.
How to mount a GCP compute instance filesystem locally using `sshfs` on MacOS

How to mount a GCP compute instance filesystem locally using sshfs

This guide assumes that:

  • you already have an instance set up on GCP that you want to mount locally
  • the GCP CLI (gcloud) is installed on your local machine
  • you have authenticated locally to your google account gcloud auth login
  1. make sure your gcloud config is correct for the instance you're trying to access:
gcloud config configurations list
  1. make a directory at the location you want to mount the file system, for example:
mkdir mnt/
mkdir mnt/<boxname>
  1. populate your ~/.ssh/config file with aliases for the instances in your project using gcloud compute config-ssh
  2. Download and install sshfs and FuseOSX: https://github.com/osxfuse/osxfuse/wiki/SSHFS#installation
  3. mount away!
sshfs -o IdentityFile=~/.ssh/google_compute_engine \
<username>@<insance-name>.<region>.<project>:/path/to/location \
<path/to/local/mount/folder>

Unmounting:

umount <path/to/local/mount/folder>

@mel4tonin4
Copy link

Thanks!

@benhannel
Copy link

This was exactly what I needed! Thanks for putting it together.

@Loerbri
Copy link

Loerbri commented Jan 15, 2020

I can ssh into my instance just fine, but following your instructions results in:
remote host has disconnected

Any ideas?

@KelSolaar
Copy link

@Loerbri: did you try to add -odebug,sshfs_debug,loglevel=debug to sshfs?

@astro313
Copy link

astro313 commented Feb 12, 2021

I can ssh into my instance just fine, but following your instructions results in:
remote host has disconnected

Any ideas?

The instruction here was working for me until I upgraded the instance, then I started getting remote host has disconnected.
@Loerbri, were you able to find a solution around this? If not, take a look at https://stackabuse.com/how-to-fix-warning-remote-host-identification-has-changed-on-mac-and-linux/

@bdabrowski
Copy link

bdabrowski commented Dec 2, 2021

I succeeded after adding an additional chunk of configuration. Your instance must have the ability to SSH using "other client".

As I understand the process GCP adds an extra layer of security before allowing for ssh like connection. I followed instructions here: https://cloud.google.com/compute/docs/instances/connecting-advanced

and configured OSLogin (recommended way).

So it doesn't seem like -o IdentityFile=~/.ssh/google_compute_engine is possible anymore. It needs to be generated separately on the machine and added during OS Login setup. Exactly as described in the link. Also as target host needed to use IP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment