Mount Google Drive on Linux (Debian) Server

For mounting Google Drive on your server. you will require two things.

  1. A project created and configured with OAuth client id and scecret on Google
  2. google-drive-ocamlfuse installed and configured

Create Project

1. go  to  https://console.developers.google.com/apis/dashboard

and create new project

Click on create credentials

Select OAuth Client ID

Click on configure Consent Screen

Provide email address and product name

To Create Client ID select others and provide Name and click on create

It will give you OAuth Client ID and Secret. Please note it down and keep safe.

Installation of google-drive-ocamlfuse On debian 9

  1. First install the required packages

apt-get install libcurl4-gnutls-dev libfuse-dev libgmp-dev libsqlite3-dev camlp4-extra debianutils libcurl4-gnutls-dev perl  m4 pkg-config zlib1g-dev

2. adduser <user> fuse ( adding user to group fuse usrmod also works)

3.  Set the Permissions

#sudo chown root.fuse /dev/fuse
#sudo chmod 660 /dev/fuse

4. Install Google Drive Ocamlfuse

# su <user>
# opam init
# opam update
# opam install depext
# eval `opam config env`
# opam depext google-drive-ocamlfuse
# opam install google-drive-ocamlfuse
# . /home/*user*/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true

#/home/user/.opam/system/bin/google-drive-ocamlfuse -headless -label googledrive -id <OAuth Client ID> -secret <OAuth Client Secret>

It will give you one url ask you to visit that url and get the code from the webpage and provide it

Open that url in browser and copy paste  the verification code to termianl

create mount point

# mkdir /mnt/Google-drive

#  /home/user/.opam/system/bin/google-drive-ocamlfuse -label googledrive /mnt/Google-drive/

Above command will enable that mount only for the user and not others not even root

To enable mount point for user root

edit file /etc/fuse.conf and uncomment below line

#user_allow_other

Then run below command

sudo -u user /home/user/.opam/system/bin/google-drive-ocamlfuse -o allow_root -label googledrive /Google-drive/ > /var/log/gdrive_mount.log 2>&1 &

Add below line (/etc/rc.local)

sudo -u  user /home/user/.opam/system/bin/google-drive-ocamlfuse -o allow_root -label googledrive /Google-drive/  2>$1  &

Thus only user and root will be able to use mounted drive.