Google Drive¶
To integrate Google Drive with a Debian Linux instance running on Google Cloud Platform (GCP) use a tool called google-drive-ocamlfuse. This tool allows to mount a Google Drive as a filesystem on the Linux instance.
1. Install google-drive-ocamlfuse¶
Install required libraries for
google-drive-ocamlfuse:sudo apt-get install software-properties-common sudo apt-get install python3-launchpadlibAdd the repository for
google-drive-ocamlfuse:sudo add-apt-repository ppa:alessandro-strada/ppaThe repository should contain the following 2 lines. Edit the repository:
sudo nano /etc/apt/sources.list.d/alessandro-strada-ubuntu-ppa-bookworm.listIf necessary, add the following 2 lines in that repository:
deb http://ppa.launchpad.net/alessandro-strada/ppa/ubuntu xenial main deb-src http://ppa.launchpad.net/alessandro-strada/ppa/ubuntu xenial mainIf necessary, download key from keyservers directly into the trusted set of keys (see Install ‘google-drive-ocamlfuse’ on Debian Stretch & Buster):
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AD5F235DF639B041Install
google-drive-ocamlfuse:sudo apt install google-drive-ocamlfuse
2. Authenticate google-drive-ocamlfuse with the Google Account¶
To authenticate
google-drive-ocamlfusewithout using a browser, use a headless authentication method provided by Google.
Generate OAuth2 Credentials:
Go to the Google Cloud Console: https://console.cloud.google.com/.
Create a new project or select an existing one.
Navigate to the “APIs & Services” > “Credentials” section.
Click on “Create credentials” and select “OAuth client ID”.
Choose “Desktop app” as the application type.
Click “Create” and note down the generated Client ID and Client Secret.
Run the Authentication Command:
Open a terminal on your VM.
Run the following command to start the authentication process:
google-drive-ocamlfuse -headless -id <CLIENT_ID> -secret <CLIENT_SECRET>Replace
<CLIENT_ID>and<CLIENT_SECRET>with the values obtained from the Google Cloud Console.Example:
google-drive-ocamlfuse -headless -id 701070352033-7j2jmeotq77mtkg60dsc9q6hris4pvj3.apps.googleusercontent.com -secret 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Follow the Authentication Flow:
The command will provide a URL and a verification code.
Copy the URL and open it in a browser on your local machine.
Sign in with your Google account if prompted and grant permission to the application.
After granting permission, you’ll receive a verification code.
Enter the Verification Code:
Copy the verification code provided by Google.
Paste the code into the terminal where the
google-drive-ocamlfusecommand is running.Press Enter.
Complete Authentication:
Once the verification code is entered,
google-drive-ocamlfuseshould complete the authentication process.You should see a message indicating successful authentication.
3. Set Google Drive API¶
Set Google Drive API in the Google Cloud account for setting the API.
4. Set mounting directory¶
Create a directory where to mount the Google Drive and then mount it using google-drive-ocamlfuse:
cd /usr/local/logistics sudo mkdir google-driveFix Permission issues if happened:
sudo chown $USER:$USER /usr/local/logistics/google-drive sudo chmod 777 /usr/local/logistics/google-drive
5. Mount and umount Google Drive¶
Mount Google Drive:
google-drive-ocamlfuse /usr/local/logistics/google-driveUnmount Google Drive:
fusermount -u /usr/local/logistics/google-drive
6. Mount automatically with crontab¶
As a prerequisite allow option
user_allow_otherinfuse, so that read/write access works on Google Drive:sudo nano /etc/fuse.confSet the following parameter in
fuse.conf:# Allow non-root users to specify the allow_other or allow_root mount options. user_allow_otherTo mount Google Drive automatically on system boot, add a line to the crontab file:
crontab -eAdd the following line to the end of the file with the path to the mount point:
# Mount google-drive with google-drive-ocamlfuse: @reboot /usr/bin/google-drive-ocamlfuse -label default -o allow_other -verbose /usr/local/logistics/google-driveNow, the Google Drive should be mounted automatically on system boot and persist through reboots.