This guide walks you through the steps to mount Google drive locally using Rclone and then backup files to google drive using Rclone in Linux operating systems. This guide has been officially tested on Manjaro Linux, but the steps are same for all Linux and Unix distributions.
Before getting started, make sure you've installed Rclone on your Linux machine. The following link contains the Rclone installation steps for Linux and Unix operating systems.
In order to mount Google drive using Rclone on your local file manager, you need to get a token from the Google drive. You can do it in two ways, from the command line using 'rclone config' command and from rclone WebUI.
Let us see the command line way first.
Table of Contents
Configure Rclone to access Google drive from commandline
Open the Terminal and run the following command to authorize Rclone to access your Google drive:
$ rclone config
This will guide you through an interactive setup process.
First, Rclone will search for a list of available remotes (i.e. Cloud providers).
Since it is our new setup, we haven't created any remotes yet. So let us create a new remote.
To create a new remote, simply type "n"
and hit ENTER
. Then type the name of the remote. Here, I am going to name it as "mygdrive".
2022/01/19 16:13:42 NOTICE: Config file "/home/ostechnix/.config/rclone/rclone.conf" not found - using defaults No remotes found - make a new one n) New remote s) Set configuration password q) Quit config n/s/q> n name> mygdrive
A list of supported cloud providers will be displayed. Choose the cloud provider of your choice. In our case. it is Google drive, so I entered number 16.
Option Storage. Type of storage to configure. Enter a string value. Press Enter for the default (""). Choose a number from below, or type in your own value. 1 / 1Fichier \ "fichier" 2 / Alias for an existing remote \ "alias" 3 / Amazon Drive \ "amazon cloud drive" 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, SeaweedFS, and Tencent COS \ "s3" 5 / Backblaze B2 \ "b2" 6 / Better checksums for other remotes \ "hasher" 7 / Box \ "box" 8 / Cache a remote \ "cache" 9 / Citrix Sharefile \ "sharefile" 10 / Compress a remote \ "compress" 11 / Dropbox \ "dropbox" 12 / Encrypt/Decrypt a remote \ "crypt" 13 / Enterprise File Fabric \ "filefabric" 14 / FTP Connection \ "ftp" 15 / Google Cloud Storage (this is not Google Drive) \ "google cloud storage" 16 / Google Drive \ "drive" 17 / Google Photos \ "google photos" 18 / Hadoop distributed file system \ "hdfs" 19 / Hubic \ "hubic" 20 / In memory object storage system. \ "memory" 21 / Jottacloud \ "jottacloud" 22 / Koofr \ "koofr" 23 / Local Disk \ "local" 24 / Mail.ru Cloud \ "mailru" 25 / Mega \ "mega" 26 / Microsoft Azure Blob Storage \ "azureblob" 27 / Microsoft OneDrive \ "onedrive" 28 / OpenDrive \ "opendrive" 29 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH) \ "swift" 30 / Pcloud \ "pcloud" 31 / Put.io \ "putio" 32 / QingCloud Object Storage \ "qingstor" 33 / SSH/SFTP Connection \ "sftp" 34 / Sia Decentralized Cloud \ "sia" 35 / Sugarsync \ "sugarsync" 36 / Tardigrade Decentralized Cloud Storage \ "tardigrade" 37 / Transparently chunk/split large files \ "chunker" 38 / Union merges the contents of several upstream fs \ "union" 39 / Uptobox \ "uptobox" 40 / Webdav \ "webdav" 41 / Yandex Disk \ "yandex" 42 / Zoho \ "zoho" 43 / http Connection \ "http" 44 / premiumize.me \ "premiumizeme" 45 / seafile \ "seafile" Storage> 16
Enter your Google drive client ID and its secret if you already have them. If you don't have client ID, you can create a new one.
Note: Please note that creating Google application client id is optional, but recommended. To know how to create your own Google drive client ID, refer this link. If you don't want to create the client ID, no problem! You can simply leave it blank and continue the other steps.
I already have created Google Application Client ID and its secret, so I entered the details below.
Option client_id. Google Application Client Id Setting your own is recommended. See https://rclone.org/drive/#making-your-own-client-id for how to create your own. If you leave this blank, it will use an internal key which is low performance. Enter a string value. Press Enter for the default (""). client_id> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com Option client_secret. OAuth Client Secret. Leave blank normally. Enter a string value. Press Enter for the default (""). client_secret> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
If you don't have Google client ID, simply press ENTER to leave blank values for Google application client id and client secret:
Google Application Client Id - leave blank normally. client_id> Google Application Client Secret - leave blank normally. client_secret>
Type 1 (Number 1) to give full access to your Google drive files. Again, it is your choice. If you don't want to give full access, you can any one of other choices.
Choose a number from below, or type in your own value.
1 / Full access all files, excluding Application Data Folder.
\ "drive"
2 / Read-only access to file metadata and file contents.
\ "drive.readonly"
/ Access to files created by rclone only.
3 | These are visible in the drive website.
| File authorization is revoked when the user deauthorizes the app.
\ "drive.file"
/ Allows read and write access to the Application Data folder.
4 | This is not visible in the drive website.
\ "drive.appfolder"
/ Allows read-only access to file metadata but
5 | does not allow any access to read or download file content.
\ "drive.metadata.readonly"
scope> 1
At the "root_folder_id
" and "service_account_file
" prompt, just leave them blank and press ENTER to accept the default values.
Option root_folder_id. ID of the root folder. Leave blank normally. Fill in to access "Computers" folders (see docs), or for rclone to use a non root folder as its starting point. Enter a string value. Press Enter for the default (""). root_folder_id> ##Leave blank and press ENTER Option service_account_file. Service Account Credentials JSON file path. Leave blank normally. Needed only if you want use SA instead of interactive login. Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`. Enter a string value. Press Enter for the default (""). service_account_file> ##Leave blank and press ENTER
Next, you are asked if you want to edit advanced configuration file. I just don't want to edit it, so I entered "n" and hit ENTER to continue.
Edit advanced config?
y) Yes
n) No (default)
y/n> n
Finally, press "Y" to use auto config (which is the default) to complete Rclone configuration task.
Use auto config?
* Say Y if not sure
* Say N if you are working on a remote or headless machine
y) Yes (default)
n) No
y/n> y
Now your web browser will open and you will be prompted to choose a Google account to continue. If you're logged in to multiple Google accounts, choose the one that you want to allow Rclone to access your Google drive.
Please note that if you newly created an app from Google API Console while creating client_id, you will see a security warning as shown below. It is normal. Google usually take a few weeks to verify the submitted app.
You can simply go ahead by clicking "Advanced" link and then click "Go to rclone (unsafe)" link.
Next Rclone will ask your permission to access your Google drive. Click "Continue" button to authorize Rclone to access your Google drive.
You will see a success message in the browser.
Just close the browser window and go back to the Terminal.
Next, you're prompted if you want to make your Google drive as a shared drive. Type "n" (It is the default) and hit ENTER.
Configure this as a Shared Drive (Team Drive)?
y) Yes
n) No (default)
y/n> n
The new remote details will displayed in the Terminal for verification. If everything seems OK, simply type "y"
and press ENTER to continue creating the remote:
y) Yes this is OK e) Edit this remote d) Delete this remote y/e/d> y
Done! A new remote named "mygdrive" has just been created.
If you wish to create another remote for different provider, click "n"
and follow the same procedure as shown above. Or, just quit the rclone configuration wizard by pressing "q"
.
Current remotes:
Name Type
==== ====
mygdrive drive
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q
You can view the list of configured remotes at any time by using the following command:
$ rclone listremotes
Sample output:
mygdrive:
Mount Google Drive Locally Using Rclone
In order to access the contents of Google drive from your file manager, you need to mount it first.
Create a mount point to mount your google drive. I am going to create a new mount point named gdrive.
$ mkdir ~/gdrive
Next, mount the Google drive using Rclone as shown below:
$ rclone mount mygdrive: ~/gdrive/
Here, "mygdrive" is the remote name and "gdrive" is the mount point name. Replace them with your own values.
Now, open your file manager and you will see that the gdrive folder is mounted in the left side. Click on it to access the contents of your Google drive.
From now on, you can create, copy, move, rename and delete files/folders as the way you do in your local file manager. Anything you put in the local mount folder (i.e. ~/gdrive
folder) will be uploaded to your Google drive.
You can also mount a specific directory/file from the google drive like below.
$ rclone mount remote:path/to/files /path/to/local/mount
You can do everything from commandline as well.
List google drive contents
To view all files in your Google drive from commandline, run:
$ rclone ls mygdrive:
Again, replace "mygdrive" using your own remote name.
To list all directories in the top level, run:
$ rclone lsd mygdrive:
Copy files and directories to Google drive
For example, to copy a directory from your local system, say "~/test"
to a directory called "ostechnix" in your Google drive, run:
$ rclone copy ~/test mygdrive:ostechnix
Sync files with Google drive
You should use this command with caution. Because, the Destination is updated to match Source, including deleting files if necessary.
Since Synchronization involves deletion on destination, it is always a best practice to first test the Synchronization operation with the --dry-run
or the --interactive
/-i
flag to avoid data loss.
rclone sync -i SOURCE remote:DESTINATION
Rclone has many other command line options. We will cover them in a separate guide soon.
Unmount Google drive
To unmount the Google drive, go to the Terminal window where you run the "rclone mount
" command and simply press "CTRL+c"
to stop the mount.
You can also do it from the file manager as well. From the file manager, right click on the mount point i.e. "gdrive" and click Unmount.
The umount operation may fail, for example when the mount point is busy. When that happens, you can stop the mount manually using command:
$ fusermount -u ~/gdrive
Conclusion
In this guide, we looked at how to mount Google drive locally with Rclone in Linux, and two basic operations - how to copy and sync the files from local drive to Google drive.
Resource:
7 comments
Well, I have made a misstep in creating an Oauth screen. Google wants a domain to publish my ‘app’ and I don’t have one.
Try to create a new app. Or use the Rclone default client ID. It should work.
I’ll try using default. but just to let you know, google apparently is requiring all kinds of publishing information.
Thanks for this. worked perfectly and easier than some of the other rclone steps I have seen. But what do I do to be able to close the terminal after? When I go to close it says that a process is still running and that closing terminal will kill it. Do I need to just leave the terminal open if I want to keep my drive mounted? Only been using linux for a total of 6 days so still learning!
Yes, Rclone will be terminated if you close the terminal session. Here is a workaround to keep your drive mounted after closing the terminal.
Add the ampersand symbol (&) at the end of rclone mount command like below.
$ rclone mount mygdrive: ~/gdrive/ &
Then run this command:
$ disown
The ampersand will run the task in the background and ‘disown’ will allow it to run even after you close your session. This will stop running once you reboot.
what we especially need to know
this is how the google drive api keys were generated
it indicates zero here thank you
We attached the official link to create Google drive client ID in the article. I leave it here for your reference. https://rclone.org/drive/#making-your-own-client-id