Linux下使用rclone挂载网盘到本地

Rclone 是一个支持挂载多数国外网盘的工具。

Rclone官网传送们

目前 Rclone 支持挂载的网盘有:Google Drive、 Dropbox 、Google Cloud Storage 、Microsoft One Drive 、Hubic、 Backblaze B2 、Yandex Disk 、Openstack Swift / Rackspace cloud files / Memset Memstore 等。更强大的是,Rclone 还支持 SFTP 、FTP 、HTTP 挂载。

配置步骤(以 Ubuntu 为例)

第一步:安装 rclone

1
2
3
4
5
方法一:rclone一键安装脚本
curl https://rclone.org/install.sh | sudo bash

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

第二步:授权(以 onedrive 为例)

1
rclone authorize "onedrive"

会出现以下信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2018/01/23 20:28:56 NOTICE: Config file "C:\\Users\\Administrator\\.config\\rclo
ne\\rclone.conf" not found - using defaults
Choose OneDrive account type?
* Say b for a OneDrive business account
* Say p for a personal OneDrive account
b) Business
p) Personal
b/p> p #这里选择个人版,你想挂载Business就选择b
If your browser doesn't open automatically go to the following link: http://127.
0.0.1:53682/auth #接下来会弹出浏览器,要求你登录账号进行授权
Log in and authorize rclone for access
Waiting for code...
Got code
Paste the following into your remote machine --->
{"access_token":"xxxx"} #请复制{xx}整个内容,后面需要用到
<---End paste

第三步:配置(链接网盘,以 onedrive 为例)

1
rclone config

会出现以下信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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> 14 #选择14,Microsoft OneDrive
Microsoft App Client Id - leave blank normally.
client_id> #留空
Microsoft App Client Secret - leave blank normally.
client_secret> #留空
Remote config
Choose OneDrive account type?
* Say b for a OneDrive business account
* Say p for a personal OneDrive account
b) Business
p) Personal
b/p> p #这里选择个人版,你想挂载Business就选择b
Use auto config?
* Say Y if not sure
* Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n> n #选择n
For this to work, you will need rclone available on a machine that has a web browser available.
Execute the following on your machine:
rclone authorize "onedrive"
Then paste the result below:
result> {"access_token":""} #输入之前在客户端授权的内容
--------------------
[Rats]
client_id =
client_secret =
token = {"access_token":""}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y # 选择y
Current remotes:

Name Type
==== ====
Rats onedrive

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退出

第四步:网盘挂载

挂载为目录

1
2
3
4
5
6
举例:
目标:将rclone中的OneDrive挂载到本地/home/songtianlun/onedrive目录下,并清空本地目录内容(--allow-non-empty

rclone mount OneDrive: /home/songtianlun/onedrive --allow-non-empty

注:网盘目录和本地目录名称不可一致,否则报错

利用 Screen 让 Rclone 在后台运行

1
screen -S onedrive

之后再运行挂载命令。

挂载完成后再用快捷键CTRL-a d 来暂时断开当前会话。最后用screen -r <screen_pid>重新连接上。

若没有安装 Screen,可以使用如下命令安装:

1
2
yum install screen  #centos系统
apt-get install screen #debian/ubuntu系统

挂载效果:

第五步:卸载磁盘

1
2
3
fusermount -qzu LocalFolder

# LocalFolder 为本地挂载目录

常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
rclone config – 以控制会话的形式添加rclone的配置,配置保存在.rclone.conf文件中。 
rclone copy – 将文件从源复制到目的地址,跳过已复制完成的。
rclone mount-挂载
rclone sync – 将源数据同步到目的地址,只更新目的地址的数据。
rclone move – 将源数据移动到目的地址。
rclone delete – 删除指定路径下的文件内容。
rclone purge – 清空指定路径下所有文件数据。
rclone mkdir – 创建一个新目录。
rclone rmdir – 删除空目录。
rclone check – 检查源和目的地址数据是否匹配。
rclone ls – 列出指定路径下所有的文件以及文件大小和路径。
rclone lsd – 列出指定路径下所有的目录/容器/桶。
rclone lsl – 列出指定路径下所有文件以及修改时间、文件大小和路径。
rclone md5sum – 为指定路径下的所有文件产生一个md5sum文件。
rclone sha1sum – 为指定路径下的所有文件产生一个sha1sum文件。
rclone size – 获取指定路径下,文件内容的总大小。
rclone version – 查看当前版本。
rclone cleanup – 清空remote。
rclone dedupe – 交互式查找重复文件,进行删除/重命名操作。

参考文献


Linux下使用rclone挂载网盘到本地
https://www.frytea.com/post/20190507075800.html
作者
Tianlun Song
发布于
2019年5月7日
更新于
2024年6月10日
许可协议