在Debian/Ubuntu上使用rclone挂载Google Drive网盘

本文介绍了如何使用rclone在Debian/Ubuntu系统中挂载GoogleDrive网盘,利用其免费或无限空间进行离线下载。通过安装rclone、初始化配置和挂载操作,可以轻松实现资源的离线存储与访问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

说明:我们很多人喜欢用VPS做离线下载,不过由于有的服务器硬盘太小了,装不了太多电影资源啥的,我们就需要想办法了,这里说个挂载Google Drive网盘的方法,毕竟Google Drive15G免费的空间,有的也有无限空间,都可以利用上去。

安装

本教程只适用Debian/Ubuntu系统。

1、安装rclone

wget https://www.moerats.com/usr/shell/rclone_debian.sh && bash rclone_debian.sh

2、初始化配置

rclone config

会出现以下信息:

n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> Rats  #随便填,后面要用到
Type of storage to configure.
Choose a number from below, or type in your own value
 1 / Amazon Drive
   \ "amazon cloud drive"
 2 / Amazon S3 (also Dreamhost, Ceph, Minio)
   \ "s3"
 3 / Backblaze B2
   \ "b2"
 4 / Box
   \ "box"
 5 / Cache a remote
   \ "cache"
 6 / Dropbox
   \ "dropbox"
 7 / Encrypt/Decrypt a remote
   \ "crypt"
 8 / FTP Connection
   \ "ftp"
 9 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
10 / Google Drive
   \ "drive"
11 / Hubic
   \ "hubic"
12 / Local Disk
   \ "local"
13 / Microsoft Azure Blob Storage
   \ "azureblob"
14 / Microsoft OneDrive
   \ "onedrive"
15 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
16 / Pcloud
   \ "pcloud"
17 / QingCloud Object Storage
   \ "qingstor"
18 / SSH/SFTP Connection
   \ "sftp"
19 / Webdav
   \ "webdav"
20 / Yandex Disk
   \ "yandex"
21 / http Connection
   \ "http"
Storage> 10  #选择10,Google Drive
Google Application Client Id - leave blank normally.
client_id>  #留空 
Google Application Client Secret - leave blank normally.
client_secret>  #留空
Service Account Credentials JSON file path - needed only if you want use SA instead of interactive login.
service_account_file> 
Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine or Y didn't work
y) Yes
n) No
y/n> n  #选择n
If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/auth....  #复制到浏览器打开,获取验证码
Log in and authorize rclone for access
Enter verification code>  #填入上面获取到的验证码
Configure this as a team drive?
y) Yes
n) No
y/n> y  #选择y
Fetching team drive list...
No team drives found in your account--------------------
[Rats]
client_id = 
client_secret = 
service_account_file = 
token = {"access_token":"ya29.GltFBd7UJN2qrxdG8FnG_rMuB18ogb8QlujdL7glvXtfV"}
team_drive = 
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y  #选择y
Current remotes:

Name                 Type
====                 ====
Rats                 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  #选择q退出

3、挂载为磁盘

#新建本地文件夹,路径自己定,即下面的LocalFolder
mkdir /root/GoogleDrive
#挂载为磁盘
rclone mount DriveName:Folder LocalFolder --allow-other &

DriveName为初始化配置填的nameFolderGoogle Drive里的文件夹,LocalFolderVPS上的本地文件夹。

挂载成功后,输入df -h命令查看即可!

4、卸载磁盘

fusermount -qzu LocalFolder

自启动

1、下载并编辑脚本
使用命令:

wget http://d.oa3.cc/sh/rcloned && nano rcloned

修改一下内容:

NAME=""  #rclone name名,及配置时输入的Name
REMOTE=''  #远程文件夹,Google Drive网盘里的挂载的一个文件夹
LOCAL=''  #挂载地址,VPS本地挂载目录

2、设置自启
使用命令:

mv rcloned /etc/init.d/rcloned
chmod +x /etc/init.d/rcloned
update-rc.d -f rcloned defaults
如果是centos:echo "/etc/init.d/rcloned start" >> /etc/rc.d/rc.local
bash /etc/init.d/rcloned start

检测信息显示rclone启动成功即可。

### 使用 FreeFileSync 和 Rsync 实现 D 盘数据备份至网盘 对于 Windows 用户而言,FreeFileSync 是一款简单易用的图形化工具,可以设置定时任务来实现文件夹之间的同步工作。通过配置计划任务,在特定时间触发 FreeFileSync 执行增量同步操作,从而确保源目录中的更改能够及时反映到目标位置[^1]。 然而,当涉及到将本地计算机上的文件同步到云端存储时,则推荐采用更为灵活且功能丰富的命令行工具——Rsync 来完成这项任务。此工具不仅支持跨平台使用,还具备高效的数据传输机制以及多种加密方式保障安全性[^2]。 具体实施方案如下: #### 方法一:利用 Rsync 结合 WebDAV 或 FTP 协议上传至网盘 如果所选网盘服务商提供 WebDAV 接口访问权限的话,那么可以直接借助 rsync 命令配合 davfs2 工具挂载远程资源作为本地文件系统的一部分;而对于仅开放FTP/SFTP接入的情况,则可通过 lftp 程序建立连接并调用内置的 mirror 功能来进行双向同步。 ```bash # 安装必要的软件包 (以 Debian/Ubuntu 发行为例) sudo apt-get install rsync lftp # 创建脚本用于定期执行同步动作 cat << EOF > ~/backup_to_cloud.sh #!/bin/bash SOURCE="/mnt/d/" DEST="davs://username:password@webdav.example.com/path/to/folder" lftp -c "open '$DEST'; mirror --reverse --delete $SOURCE /" EOF chmod +x ~/backup_to_cloud.sh ``` #### 方法二:基于 Python 脚本自动化 Alist 同步过程 针对某些特殊场景下可能存在的兼容性问题或是更复杂的业务需求,也可以考虑编写自定义逻辑驱动整个流程运转。下面给出了一段来自 Gitee 平台托管项目 `alist-sync` 中提供的快速入门指南片段,适用于青龙面板环境下的部署实践[^3]。 ```python import requests from pathlib import Path def sync_files(source_dir, target_url): source_path = Path(source_dir).resolve() for item in source_path.iterdir(): if not item.is_file(): continue with open(item,'rb') as f: files={'file':f} resp=requests.post(target_url+'/upload',files=files) if __name__=='__main__': d_drive='D:\\' cloud_endpoint='https://your-alist-instance/api/file/upload' try: sync_files(d_drive,cloud_endpoint) print('Sync completed successfully.') except Exception as e: print(f'Error occurred during syncing:{str(e)}') ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值