1
2022-12-18 17:12:33 +00:00

239 lines
12 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/jpg" href="https:&#x2F;&#x2F;branding.ewpratten.com&#x2F;pfp&#x2F;2022&#x2F;460x460.webp" />
<link rel="canonical" href="https:&#x2F;&#x2F;ewpratten.com&#x2F;blog&#x2F;mounting-google-drives&#x2F;" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="https://ewpratten.com/rss.xml">
<meta name="twitter:card" content="summary" />
<meta name="og:site" content="ewpratten.com" />
<meta name="og:site_name" content="Evan Pratten" />
<meta name="og:image"
content="https:&#x2F;&#x2F;branding.ewpratten.com&#x2F;pfp&#x2F;2022&#x2F;460x460.webp" />
<meta property="og:description" content="Easy-to-use Google Drive integration for Linux using rclone" />
<meta property="description" content="Easy-to-use Google Drive integration for Linux using rclone" />
<meta name="description" content="Easy-to-use Google Drive integration for Linux using rclone">
<meta property="og:title" content="Mounting Google Drive accounts as network drives - Evan Pratten" />
<meta property="og:type" content="article" />
<title>Mounting Google Drive accounts as network drives | Evan Pratten</title>
<link rel="stylesheet" href="/global.css">
<link rel="stylesheet" href="/dist/github-markdown-css/github-markdown-light.css" lazyload>
<link rel="stylesheet" href="/styles/bootstrap.css" lazyload>
<link rel="stylesheet" href="/styles/typography.css">
</head>
<body>
<div class="page">
<link rel="stylesheet" href="/styles/components/heading-card.css">
<div class="heading-card">
<div class="profile-photo-container">
<img src="https:&#x2F;&#x2F;branding.ewpratten.com&#x2F;pfp&#x2F;2022&#x2F;460x460.webp" alt="Profile Photo" loading="lazy">
</div>
<div class="text-container">
<h1>Evan Pratten</h1>
<p>Software Developer</p>
</div>
</div>
<div class="container">
<link rel="stylesheet" href="/styles/components/navbar.css">
<div class="ewp-navbar">
<hr>
<ul class="navbar-items">
<li><a href="/">Home</a></li>
<li class="separator">|</li>
<li><a href="/timeline">Timeline</a></li>
<li class="separator">|</li>
<li class="dropdown-center">
<a href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
More
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="/photography">Photography</a></li>
<li><a class="dropdown-item" href="/contact">Contact</a></li>
</ul>
</li>
</ul>
<hr>
</div>
</div>
<article id="content" class="container markdown-body">
<h1 style="margin-bottom:0;padding-bottom:0;">Mounting Google Drive accounts as network drives</h1>
<em>Easy-to-use Google Drive integration for Linux using rclone</em>
<br><br>
<p>When sharing files, I use three main services. I use <a rel="noopener" target="_blank" href="https://en.wikipedia.org/wiki/Firefox_Send">Firefox Send</a> and <a rel="noopener" target="_blank" href="https://book.keybase.io/docs/files">KeybaseFS</a> to share one-off and large files with friends, and I use <a rel="noopener" target="_blank" href="https://drive.google.com">Google Drive</a> to store some personal files, and for everything school-related (I don't get a choice about this). For the first two services, sharing a file is as simple as calling <a rel="noopener" target="_blank" href="https://github.com/timvisee/ffsend"><code>ffsend</code></a> or moving a local file into my kbfs mountpoint, and I am done. Google Drive, on the other hand, the process isn't as easy. While some Linux distributions have Google Drive integration out of the box (I miss daily-driving <a rel="noopener" target="_blank" href="https://www.chromium.org/chromium-os">ChromiumOS</a>), Linux users generally have to go to <code>drive.google.com</code>, and deal with the Google Drive webapp. Not sure if this is an &quot;only me&quot; problem, but whenever I need to quickly make a change to a document through the webapp, It decides to stop working.</p>
<p>I really like the Keybase approach of mounting remote storage as a &quot;network drive&quot; on my laptop, and wanted to do something similar for Google Drive. This is where a great tool called <a rel="noopener" target="_blank" href="https://rclone.org"><code>rclone</code></a> comes in to play. Rclone is a very easy-to-use command-line application for working with cloud storage. I originally learned about it when I used to host this website on <a rel="noopener" target="_blank" href="https://www.digitalocean.com/products/spaces/">DigitalOcean Spaces</a> a few years ago. Out of the box, Rclone supports <a rel="noopener" target="_blank" href="https://rclone.org/#providers">many cloud providers</a>, including Google Drive!</p>
<h2 id="setting-up-rclone-for-use-with-google-drive">Setting up Rclone for use with Google Drive</h2>
<p>Now for the fun part, to get started with Rclone and Google Drive on your computer, you must first install Rclone. I am going to assume you are using a Linux-based operating system here, but with some slight tweaking, this works on BSD and Windows too!</p>
<pre data-lang="sh" style="background-color:#2b303b;color:#c0c5ce;" class="language-sh "><code class="language-sh" data-lang="sh"><span style="color:#65737e;"># Install Rclone with the automated installer
</span><span style="color:#bf616a;">curl</span><span> https://rclone.org/install.sh | </span><span style="color:#bf616a;">sudo</span><span> bash
</span></code></pre>
<p>Once Rclone is installed, you need to hop on over to the <a rel="noopener" target="_blank" href="https://console.developers.google.com/">Google Cloud Developer Console</a>, and create a new project. Under the <em>ENABLE APIS AND SERVICES</em> section, search for, and enable the <code>Google Drive API</code>. This will expose an API to your Google Drive, and let programs interact with the files (if setting up multiple accounts, you only need to enable the API on one of them). Click the <em>Credentials</em> tab in the left-side panel, then <em>Create credentials</em>. This will open a panel letting you set up access to your new API.</p>
<p>With the panel open, click <em>CONFIGURE CONSENT SCREEN</em>, <em>External</em>, then <em>CREATE</em>. Enter <code>rclone</code> as the application name, and save it. You now have set up one of those &quot;sign in with Google&quot; screens for yourself. Clicking the <em>Credentials</em> tab again will bring you to an area where you can generate the needed API keys for Rclone.</p>
<p>Click <em>+ CREATE CREDENTIALS</em> at the top of the panel, and select <em>OAuth client ID</em>. Set the application type to <em>Desktop app</em>, and finally, press <em>Create</em>. You will now be shown the needed info to link Rclone to your account(s).</p>
<div class="center" markdown="1">
*Note: This API project is **not verified** by Google.*<br>
*This means that you will be greeted with a scary warning when logging in the first time. Just ignore it.*
</div>
<p>Back in the terminal, we can run <code>rclone config</code> to set up a configuration for Google Drive. You will be prompted with many options. Use the following:</p>
<pre data-lang="sh" style="background-color:#2b303b;color:#c0c5ce;" class="language-sh "><code class="language-sh" data-lang="sh"><span style="color:#65737e;"># &gt; rclone config
</span><span>
</span><span style="color:#65737e;"># Create a new config
</span><span style="color:#bf616a;">n</span><span>) </span><span style="color:#bf616a;">New</span><span> remote
</span><span>
</span><span style="color:#65737e;"># Set a name
</span><span style="color:#bf616a;">name</span><span>&gt; my_drive
</span><span>
</span><span style="color:#65737e;"># Choose a storage type
</span><span style="color:#bf616a;">Storage</span><span>&gt; drive
</span><span>
</span><span style="color:#65737e;"># You will be asked for a client ID and secret. These are the strings we just generated
</span><span style="color:#bf616a;">...
</span><span>
</span><span style="color:#65737e;"># Set the scope to allow Rclone access to your files
</span><span style="color:#bf616a;">scope</span><span>&gt; </span><span style="color:#d08770;">1
</span><span>
</span><span style="color:#65737e;"># Select the default option for everything until asked if you want to use &quot;auto config&quot;
</span><span style="color:#65737e;"># When asked, say yes
</span><span style="color:#bf616a;">auto_config</span><span>&gt; y
</span><span>
</span><span style="color:#65737e;"># Set team drive to no
</span><span style="color:#bf616a;">team_drive</span><span>&gt; n
</span><span>
</span><span style="color:#65737e;"># Verify the information, then say yes
</span><span style="color:#bf616a;">ok</span><span>&gt; y
</span></code></pre>
<p>Almost done. You need to run <code>rclone ls my_drive:</code> (the colon is important). This will probably ask you to go to a link, and enable an API. Do so.</p>
<p>Your Google Drive can now be mounted by running the following (feel free to change the paths to whatever you want)</p>
<pre style="background-color:#2b303b;color:#c0c5ce;"><code><span>mkdir -p ~/google_drive
</span><span>rclone mount my_drive: ~/google_drive --vfs-cache-mode writes
</span></code></pre>
<h2 id="starting-rclone-on-boot">Starting Rclone on boot</h2>
<p>You probably don't want to run an <code>rclone</code> command every time you start your computer. This can be solved in one of two ways</p>
<h3 id="for-i3wm-users">For i3wm users</h3>
<p>On <code>i3wm</code>, just add the following line to <code>~/.config/i3/config</code>:</p>
<pre data-lang="sh" style="background-color:#2b303b;color:#c0c5ce;" class="language-sh "><code class="language-sh" data-lang="sh"><span style="color:#96b5b4;">exec</span><span> --no-startup-id rclone mount my_drive: /home/&lt;user&gt;/google_drive --vfs-cache-mode writes
</span></code></pre>
<p><em>Make sure to replace <code>&lt;user&gt;</code> with your username.</em></p>
<p>Keep in mind, <code>exec</code> commands are not run when reloading <code>i3</code> with <kbd>Mod</kbd>+<kbd>Shift</kbd>+<kbd>r</kbd>. You must log out (<kbd>Mod</kbd>+<kbd>Shift</kbd>+<kbd>e</kbd>), and back in again.</p>
<h3 id="for-ubuntu-debian-based-users">For Ubuntu / Debian-based users</h3>
<p>In pretty much any Debian-based system, you can edit <code>/etc/rc.local</code> (using <code>sudo</code>), and add the following line right before <code>exit 0</code>:</p>
<pre data-lang="sh" style="background-color:#2b303b;color:#c0c5ce;" class="language-sh "><code class="language-sh" data-lang="sh"><span style="color:#bf616a;">rclone</span><span> mount my_drive: /home/&lt;user&gt;/google_drive</span><span style="color:#bf616a;"> --vfs-cache-mode</span><span> writes
</span></code></pre>
<p><em>Make sure to replace <code>&lt;user&gt;</code> with your username.</em></p>
</article>
<link rel="stylesheet" href="/styles/components/footer.css">
<div class="footer">
<br>
<span class="gray">-- EOF --</span>
<p>
Site design & content by: <a href="/contact">Evan Pratten</a><br>
Consider <a href="/donate" target="_blank">supporting my work</a> if you like what you see<br>
</p>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3"
crossorigin="anonymous"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script defer src="https://www.googletagmanager.com/gtag/js?id=G-5912H4H03P"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-5912H4H03P');
</script>
</body>
</html>