Google drive is a great FREE cloud storage service. It allows you to store your data in the cloud so you can access it anywhere in the world, from just about any device. In this Linux Quick Tip we will show you how to easily mount your Google Drive using Gnome Online Accounts. Once mounted, you can access, copy, and delete your files from the GUI or the command line.

Set Up Google Drive in Gnome Online Accounts

Let's fire up Gnome Online Accounts and add our account. Go to Settings > Online Accounts to access the Add an account screen pictured below.

Using Gnome Online Accounts to connect your Google Drive account to Linux

Click on Google and you will be asked to provide your gmail user account credentials. pass two factor authentication if enabled, and grant Gnome access to your account.

Google Account Login Dialog Box

Once you are authenticated, you will be asked what features you want access to. You can select whatever you want here. Some of my friends like to enable everything so they can use the Gnome native apps. Since this article is about mounting Google Drive in Linux, we only need to ensure Files is turned on. Make sure the switch next to Files is on, and click the x to close the dialog box.

Connecting Google Services to Gnome

Now you will see that your Google account is connected. Once you are at this point, you are ready to start using Google Drive.

Access Google Drive From Linux GUI

Now that your account is active, you can start using Google Drive. If you open "Files" you will see a new drive on the left menu with your gmail address as it's name. This is your Google Drive and you can copy, delete, and rename files from it just like you would any other folder.

Accessing Google Drive from Nautilis

Now that you can access Google Drive from your desktop, so can all of your apps. You can use your favorite backup tool (Deja Dup?) to copy your important files to Google Drive.

Access Google Drive from Linux Command Line

Here is where this became really useful for me. I wanted to access Google Drive from the command line so I can use rsync to synchronize my Documents directory with Google Drive.

Gnome uses it's gvfs (GNOME Virtual file system) to mount Google Drive with your account. The default location for a gvfs mounted drive is /run/user/<user-id>/gvfs/<connection-name>/. Of course you have to replace <user-id> with your UID and <connection-name> with the Google Drive connection name.

You can your UID by using the echo command like so:

[mcherisi@putor ~]$ echo $UID
1001

Or you can use the following command to add it on the fly:

cd /run/user/$UID/gvfs/google-drive*

Here is it in action:

[mcherisi@putor ~]$ cd /run/user/$UID/gvfs/google-drive*
[mcherisi@putor google-drive:host=gmail.com,user=********]$ ls -lrt
total 8
-rw-------. 1 mcherisi mcherisi 7177 May 22 22:42 1RHAnCZyLC3dXUd1cLTUcyJOISLkGK1QI
-rw-------. 1 mcherisi mcherisi  140 May 22 22:50 1R3-QyxlBRlLjpjpWh28ntuUaep1510VY
[mcherisi@putor google-drive:host=gmail.com,user=********]$

As you can see above, Google Drive doesn't show the "display-name" of the file, but rather the ID of the file. This can make it hard to know what file you are going to be accessing. You can get a list with the filenames by using the gio command.

[mcherisi@putor google-drive:host=gmail.com,user=********]$ gio list -a "standard::display-name"
1R3-QyxlBRlLjpjpWh28ntuUaep1510VY	0	(regular)	standard::display-name=ok.txt
1RHAnCZyLC3dXUd1cLTUcyJOISLkGK1QI	7177	(regular)	standard::display-name=Resume.txt

Because I use this so often, I created an alias to quickly get a listing. I added the following to my ~/.bashrc file.

alias lg='gio list -a "standard::display-name"'

Now I can just lg when I want a listing with the common names.

[mcherisi@putor google-drive:host=gmail.com,user=********]$ ls
1R3-QyxlBRlLjpjpWh28ntuUaep1510VY  1RHAnCZyLC3dXUd1cLTUcyJOISLkGK1QI

[mcherisi@putor google-drive:host=gmail.com,user=********]$ lg
1R3-QyxlBRlLjpjpWh28ntuUaep1510VY	0	(regular)	standard::display-name=ok.txt
1RHAnCZyLC3dXUd1cLTUcyJOISLkGK1QI	7177	(regular)	standard::display-name=Resume.txt

Now that I have this setup, I use rsync to synchronize my Documents folder with Google Drive. Now no matter where I am I can log into my gmail account and have access to all my documents. If you are interested in how this works leave a comment below!

Conclusion

There you have it, a simple method for connecting and mounting your Google drive on your Linux system. I use this every day and love it.

Resources and Links