Machine Learning Engineer, One Fourth Labs
Ever wanted to browse the files in your Google Cloud Platform’s Virtual Machine through your local file explorer? Here’s one way to do that!
First of all, follow the steps in this article mentioned below to setup keys in your local machine & GCP VM:
How to create and connect to Google Cloud Virtual Machine with SSH
Ensure that you’re able to connect to your GCP VM via SSH as directed in that article before proceeding into this article.
Note for Windows users:
Remember that you can use the same keys for any number of VMs instead of regenerating different keys.
@echo off :: OpenSSH Private Key File set KEY_PATH=C:\\Users\\GokulNC\\Desktop\\Keys\\GCP_VM\\id_rsa set USERNAME=GokulNC_GCP set REMOTE_DIR=/ set /p IP=Enter the IP: set /p DriveLetter=Enter the mount drive letter: set CYGFUSE=WinFsp set PATH=C:\Program Files (x86)\SSHFS-Win\bin;%PATH% sshfs.exe -ofstypename=SSHFS -o idmap=user -o umask=000 -o volname=%IP% -o Compression=no -o reconnect,ServerAliveInterval=120 -o IdentityFile=%KEY_PATH% %USERNAME%@%IP%:%REMOTE_DIR% %DriveLetter%: :: Wait a few secs for it to become stable timeout 3 >NUL echo. echo. IF EXIST %DriveLetter%:\ ( echo Connected to %USERNAME%@%IP% successfully and mounted %REMOTE_DIR% at %DriveLetter%:\ echo. echo Minimize this window and continue browsing your remote host's FS. echo To terminate the connection, close this window. ) ELSE ( echo Connection FAILED! Close this window. ) echo. echo. pause >NUL pause >NUL echo Connection terminated. Close this window.
That's it! Now you can browse your VM's files from Windows Explorer itself.
It’s just a matter of seconds in Linux!
sudo apt install sshfs sudo mkdir /mnt/gcpVM
To mount your VM to the above created mount-point, run the following one-line command with your username (ZZ) and VM’s external IP:
sshfs ZZ@X.X.X.X:/ /mnt/gcpVM/ -o IdentityFile=~/.ssh/id_rsa -o reconnect,ServerAliveInterval=120
That’s it, the VM's file system should have been mounted at the given path!
(I believe similar steps should be sufficient for Mac Users, let me know in comments if it doesn’t work)
To unmount, use the following command:
fusermount -u /mnt/gcpVM
Create your free account to unlock your custom reading experience.