Setting up Rclone on a remote server to connect to Google Drive can be a frustrating experience.
The problem arises when you need to authorize the connection by visiting the generated URL like http://127.0.0.1:53682/auth?state=blahblah
on your local browser.
This link won’t work on your local machine since it was generated on the remote server.
Furthermore, Rclone does offer an alternative URL for remote/headless server users, but this might result in an Access blocked: Rclone's request is invalid
error. At least that’s what happens in my case.
In this tutorial, we will guide you through a workaround using an SSH tunnel to authorize Rclone for Google Drive connection from your remote server without any issues.
Table of Contents
Pre-requisites:
- A remote server (e.g., Digital Ocean, Vultr, Hetzner, etc.)
- Rclone installed on the remote server
- SSH access to the remote server
Step 1. Begin Rclone Configuration
Start by connecting to your remote server via SSH and begin the Rclone configuration process with the following command:
rclone config
Go through the motions as you normally would with your preferred settings until you get to the auto config question.
Step 2. Say Yes to “auto config”
When you get to this question say yes. This is because, if you’ve been having my issue, if you select N you’re given a link that leads to “Rclone’s request is invalid”.
Remote config
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
If you said yes, you’re given a link like this.
http://127.0.0.1:53682/auth?state=ASDha9sd8yhd9pq-ASD
Leave it like that and open a new terminal session or Putty on your local computer.
Create an SSH Tunnel
An SSH tunnel helps by securely forwarding your local computer’s browser traffic to the remote server, allowing you to access and authorize the Rclone-generated URL as if you were on the server itself.
On your second terminal (I’m using cmder on Windows), run the following command:
ssh -L 53682:localhost:53682 -C -N -l <your_user> <your_remote_server_ip>
Replace:
<your_user>
with your actual remote server user<your_remote_server_ip>
with your remote server’s IP
The session will just hang after you enter the password.
Don’t worry, that’s normal. The tunnel is established.
This is what it will look like.
Copy Rclone Authorization Link to Your Local Browser
Now you can copy the http://127.0.0.1:53682/auth?state=ASDha9sd8yhd9pq-ASD
link and place it in your local machine’s browser and it should work to authorize your Google account.
When you’ve authorized it, you’ll get a message Success! All done. Please go back to rclone.
In your command line where you’re configuring Rclone you’ll see the configuration moves forward and will see the message:
Got code
Configure this as a team drive?
y) Yes
n) No (default)
y/n>
You can close the browser window and the terminal and move on with the config. Rclone is now authorized.
Now you can continue with your Rclone config as you normally would.
Frequently Asked Questions
What’s an SSH Tunnel?
An SSH tunnel helps by securely forwarding your local computer’s browser traffic to the remote server, allowing you to access and authorize the Rclone-generated URL as if you were on the server itself.
An SSH tunnel is a secure, encrypted connection between your local computer and a remote server, allowing you to forward local network traffic to the remote server. In this case, the SSH tunnel is created using the command ssh -L 53682:localhost:53682 -C -N -l root <remote_server_ip>
.
Here’s a breakdown of the command:
-L 53682:localhost:53682
: This flag sets up local port forwarding, mapping the local port 53682 to the remote server’s localhost at port 53682. It allows you to access the remote server’s Rclone configuration URL from your local browser.-C
: This flag enables data compression, which can help speed up the transfer of data over the tunnel.-N
: This flag tells SSH not to execute any commands on the remote server, meaning it only establishes the connection for port forwarding.-l root
: This flag specifies the remote server’s login username (in this case, ‘root’).<remote_server_ip>
: Replace this placeholder with the actual IP address of your remote server.
By creating an SSH tunnel, you can securely access resources on the remote server as if they were available locally, enabling you to complete the Rclone configuration process in this tutorial.
Conclusion
This was a short tutorial on how to connect Rclone to Google Drive. Ideally it should have worked when you tell the Rclone config that you’re using a remote/headless server. This is just a clean workaround in my opinion. Let me know of you have any feedback or encounter any issues.
very good, thank you,
works perfect.
Great work. was able to use this and make the connection.
Thanks, works perfect.
great, thank you!
Glad to help!