其实 rclone 挂载 Google Drive 网上的教程已经很多了,但是大多数的教程都有一点点过时,与现在的实际操作有一点出入,故整理了当前的挂载操作,以防忘记。
一、 安装并配置rclone
首先在vps上一键安装rclone:
curl https://rclone.org/install.sh | sudo bash
接下来在本地电脑上下载命令行操作的rclone:
访问rclone下载地址,选择您的操作系统下载相应的zip包并解压。一会需要用得着。
软件准备好中,在vps上开始配置,执行:
rclone config
您应该会看见
2022/05/28 08:56:05 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
选择n,新建配置:
此时rclone会要你选择要挂载什么网盘,找到google drive并选择。
选择后rclone会要求输入api token,如果留空会使用rclone默认的api,但是据官方说明官方的目前使用人数过多,由于google本身的限制可能会出现需要等待时间过长的问题,因此推荐自己去申请一个api。
申请api并不复杂,也不一定要是需要被挂载的google账户操作,随意一个正常的google账户就可以。下面是申请的简单步骤:
- 首先登录到Google API console,创建一个应用,点击“启用API和服务”,找到Google Drive并启用
2. 点击OAuth同意屏幕,用户类型选择外部,应用名称随便填写,比如“rclone”就可以。用户支持电子邮件和开发者联系邮箱都填写您自己的就可以,点击保存并继续,剩下的参数都是用默认就可以了。
3. 点击凭据,屏幕上方点击创建凭据,选择OAuth 客户端ID
应用类型选择桌面应用。
名称随便填,点击创建。创建后会向您提供您的客户端ID 和客户端密码,务必记下这些数据,并且填写到rclone中。
最后选择OAuth同意屏幕,选择发布应用。此时应该能看到发布状态变为了正式版。
至此Google API就申请完成了,继续返回到rclone中进行配置。
填写Google API后,应该会看到如下显示:
Scope that rclone should use when requesting access from drive.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
1 / Full access all files, excluding Application Data Folder.
\ (drive)
2 / Read-only access to file metadata and file contents.
\ (drive.readonly)
/ Access to files created by rclone only.
3 | These are visible in the drive website.
| File authorization is revoked when the user deauthorizes the app.
\ (drive.file)
/ Allows read and write access to the Application Data folder.
4 | This is not visible in the drive website.
\ (drive.appfolder)
/ Allows read-only access to file metadata but
5 | does not allow any access to read or download file content.
\ (drive.metadata.readonly)
这个可以根据需求选择,比如我要完整的访问权限,就选择1。
接下来
root_folder_id 为空,service_account_file 也为空,直接回车即可。
Edit advanced config 输入 n,不需要进行额外的高级配置。
Use auto config 因为是要在vps上挂载,vps没有桌面环境,因此必须选择 n
,进行远程配置。
选择后会看见如下显示:
Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
rclone authorize "drive" "Your Token Code"
Then paste the result.
Enter a value.
注意,接下来要在本地执行,前面下载在本地的rclone压缩包解压后,你应该能看到一个rclone.exe,类似下图
打开终端,进入到此目录后执行rclone authorize “drive”这一行。
如果不出意外,会自动打开浏览器进入到谷歌账号登录界面,此时一定要登录被挂载的谷歌账号,并选择同意授权。由于是新申请的API,没有经过的谷歌的验证,所以谷歌会提醒该应用未经验证。但是左下角有一行小灰字,点击选择继续就能授权。
授权成功浏览器会提示success:
此时返回命令行,等待几秒就能看见授权的code了。
复制授权code,输入到rclone中。
接下来rclone会询问是否为团队盘:
Configure this as a Shared Drive (Team Drive)?
y) Yes
n) No (default)
如果您要挂载的就是团队盘,那么选择y,不是的话就选择n
此时配置就已经结束了,退出clone,开始挂载。
二、 挂载Google Drive
首先新建一个文件夹用于挂载:
mkdir /google
开始挂载:
rclone mount gdrive: /google --allow-other --allow-non-empty --vfs-cache-mode writes --daemon
其中gdrive是rclone配置时输入的配置名称,/google是挂载目录,–daemon是指后台运行。
此时可能会报错:
Fatal error: mount not ready
这是现在版本的报错不太完善,需要去掉 –daemon 才能看到报错
rclone mount gdrive: /google --allow-other --allow-non-empty --vfs-cache-mode writes
一般是因为缺少依赖导致的,我们选择安装
centos系使用:
yum install -y fuse fuse3
debian系使用:
apt install -y fuse fuse3
再次执行挂载命令,如果没有报错,就是挂载成功了。
检查挂载:
df -h
应该看到:
可以看到/google已经成功挂载了
接下来进入/google进行一些简单的测试
cd /google
ls
mkdir test
rm -rf test
如果能够顺利执行,则说明挂载没有问题。
Failed to create file system for “Gd:/”: drive: failed when making oauth client: failed to create oauth client: empty token found – please run “rclone config reconnect Gd:”
为什么挂载的时候会显示这个
我没有遇到过这个问题,可以尝试检查一下API是否配置准确(包括申请的部分和rclone的填写),如果还有问题,可以尝试参考https://forum.rclone.org/t/failed-to-create-file-system-when-making-oauth-client/12324
大佬,那一步在token在电脑上面操作,具体复制哪里!下载下来的文件里面有个终端打开无法输入,我是在文件夹下起得一个终端,复制rclone authorize “drive”那一行这里的全部复制吗,加前面的复制过去也不行,不复制过去也不行,麻烦大佬解答,万分感谢
需要在https://rclone.org/downloads/中下载你本地操作系统的rclone,解压后应该能看见rclone.exe。在终端中进入此目录并输入复制的rclone authorize “drive”(是的只需要这一行,其他的不需要复制)
感谢您的反馈,已在文章中进行了更详细的描述🙂
感谢!成功了!
重启怎么自动挂载呢,可以为我解答一下吗,谢谢了!
root@localhost:~# rclone mount gdrive: /google –allow-other –allow-non-empty –vfs-cache-mode writes –daemon
2022/12/10 09:54:11 Failed to create file system for “gdrive:”: drive: failed when making oauth client: failed to create oauth client: invalid character ‘y’ looking for beginning of value
没有成功,不知道怎么回事QAQ 难道是cofing.json弄错了?
检查检查令牌、秘钥等输入是否正确吧
我加了一个/才成功的
rclone mount gdrive:/ /google –allow-other –allow-non-empty –vfs-cache-mode writes –daemon
感谢反馈,我之前没遇到这个问题,可能是由于版本更新带来的变化吧
而且获取授权的code那一步在win的终端操作的开始需要保证终端也走代理
powershell需要先输入代码:
$Env:http_proxy=”http://127.0.0.1:<代理软件的端口>”;
$Env:https_proxy=”http://127.0.0.1:<代理软件的端口>”;
而且在复制的过程中 rclone authorize “drive” 后面还有一段字符也得复制过去
获取token总是time out
检查你本机命令行是否也能正常走代理,能否连通Google
挂载的时候出现这种是因为什么呢??
Fatal error: mount not ready
新版的报错不太完善,可以去掉–deamon试试,这样才能看到报错。现在有可能是需要apt install fuse3 -y才能挂载
今天试了一把,加了apt install fuse3 -y就可以了
不用自己的OAuth 2.0 客户端 ID,默认就行
最大的难点就是cmd中要设置代理
Unable to locate package fuse3
这个怎么解决
apt update -y && apt install fuse3 -y 试试,如果不行的话,建议更新操作系统或去 https://pkgs.org/download/fuse3 看看