Ever found yourself staring at a server terminal, needing to get files to Google Drive, and thinking, "There has to be a better way than fiddling with web interfaces?" If you're running Ubuntu, especially without a graphical desktop, you're in luck. There's a tool that's become my go-to for this exact scenario: rclone.
Now, rclone isn't just for Google Drive. It's a Swiss Army knife for cloud storage, supporting over 70 different services and protocols. Think Dropbox, OneDrive, Mega, even object storage like AWS S3 and Google Cloud Storage, plus traditional protocols like FTP and SFTP. It’s incredibly versatile. But for our purposes today, we're focusing on making Google Drive sing on your Ubuntu command line.
Why rclone, you ask? Well, for starters, it's cross-platform, open-source, and completely free. Crucially for server environments, it doesn't need a graphical interface. It handles large files like a champ, with features like resumable transfers and chunking, meaning a dropped connection won't send you back to square one. Plus, you can crank up the speed with multi-threaded transfers, making full use of your bandwidth. It's built to work smoothly with the Google Drive API, which means fewer headaches down the line.
Let's get this set up. The installation is refreshingly simple. You can usually just run a single command from the official rclone website:
curl https://rclone.org/install.sh | sudo bash
This script is smart; it'll figure out your Ubuntu version and architecture and get rclone installed. If, by chance, you get a curl: command not found error, don't worry. It just means you need to install curl first:
sudo apt update && sudo apt install curl -y
Once curl is sorted, run the rclone installation script again. After installation, a quick rclone version will confirm everything is good to go.
Now for the main event: connecting rclone to your Google Drive. This is done through an interactive setup wizard. Just type rclone config and follow the prompts. It might seem a bit daunting, but I'll walk you through the key parts.
Setting Up Your Google Drive Connection
When you run rclone config, you'll be presented with a menu. Here's a breakdown of the common steps:
- New remote: Type
nand press Enter. - Name: Give your connection a memorable name.
gdriveis a popular choice, and I stick with it because it's easy to remember. Press Enter. - Storage type: You'll see a list of storage options. Find Google Drive and enter its corresponding number (it's usually 24, but check your screen). Press Enter.
- Client ID & Client Secret: For most personal use, you can leave these blank by just pressing Enter. If you're aiming for maximum speed and plan to use rclone extensively, you could set up your own API credentials, but for starters, leaving them empty is perfectly fine.
- Scope: This is crucial. You need full read/write access. Select option
1(Full access all files, excluding Application Data Folder) and press Enter. - Service Account File: This is a common pitfall! For personal Google Drive accounts, you must leave this blank. Just press Enter. Filling this in is for service accounts, which is a different use case.
- Edit advanced config: Unless you know what you're doing, type
nand press Enter to skip this. - Use web browser to automatically authenticate: This is where your setup diverges based on your environment.
- If you're on a server with no GUI (most common for cloud servers): Type
nand press Enter. This will generate a URL. You'll need to copy this URL, paste it into a browser on a computer that can access Google, log in to your Google account, grant rclone permission, and then copy the verification code back to your Ubuntu terminal. It sounds like a few steps, but it's straightforward. - If you're on your local Ubuntu desktop with a browser: Type
yand press Enter. A browser window will pop up automatically. Log in to your Google account, grant permission, and once you see a "Success" message in the browser, just press Enter back in your terminal.
- If you're on a server with no GUI (most common for cloud servers): Type
- Configure as Shared Drive: For personal Google Drive, type
nand press Enter.
Once authorized, you'll be asked to confirm and save the configuration. Press Enter to accept the default. Then, type q to exit the configuration wizard.
Troubleshooting Common Issues
If something goes wrong during configuration, the easiest fix is often to delete the faulty remote and start over. You can do this by running rclone config again, then typing d to delete, selecting the remote you want to remove (usually 1 for gdrive), and confirming with y.
After successfully configuring, you can test it with a simple command like rclone lsd gdrive: to list the top-level directories in your Google Drive. If it works, you're all set to start uploading, downloading, and syncing your files from the command line!
