Ubuntu20.04 安装Rclone挂载Onedrive
客户端授权
在本地Windows
电脑上下载rclone
,下载地址:https://rclone.org/downloads/。然后解压出来,比如我解压到D
盘,文件夹命名rclone
,此时点击Win+R
,然后输入cmd
,确定。再输入以下命令:
cd /d d:\rclone
rclone authorize "onedrive"
会出现以下信息:
C:\Users\Administrator>cd /d d:\rclone
d:\rclone>rclone authorize "onedrive"
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
安装Rclone
直接使用官方提供的一键脚本:
curl https://rclone.org/install.sh | bash
2、初始化配置
rclone config
会出现以下信息:
root@NCloud:~# rclone config
2021/12/22 10:21:07 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/s/q> s
Your configuration is not encrypted.
If you add a password, you will protect your login information to cloud services.
a) Add Password
q) Quit to main menu
a/q> q
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> onedrive5T
Option Storage.
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value.
1 / 1Fichier
\ "fichier"
2 / Alias for an existing remote
\ "alias"
3 / Amazon Drive
\ "amazon cloud drive"
4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, SeaweedFS, and Tencent COS
\ "s3"
5 / Backblaze B2
\ "b2"
6 / Better checksums for other remotes
\ "hasher"
7 / Box
\ "box"
8 / Cache a remote
\ "cache"
9 / Citrix Sharefile
\ "sharefile"
10 / Compress a remote
\ "compress"
11 / Dropbox
\ "dropbox"
12 / Encrypt/Decrypt a remote
\ "crypt"
13 / Enterprise File Fabric
\ "filefabric"
14 / FTP Connection
\ "ftp"
15 / Google Cloud Storage (this is not Google Drive)
\ "google cloud storage"
16 / Google Drive
\ "drive"
17 / Google Photos
\ "google photos"
18 / Hadoop distributed file system
\ "hdfs"
19 / Hubic
\ "hubic"
20 / In memory object storage system.
\ "memory"
21 / Jottacloud
\ "jottacloud"
22 / Koofr
\ "koofr"
23 / Local Disk
\ "local"
24 / Mail.ru Cloud
\ "mailru"
25 / Mega
\ "mega"
26 / Microsoft Azure Blob Storage
\ "azureblob"
27 / Microsoft OneDrive
\ "onedrive"
28 / OpenDrive
\ "opendrive"
29 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
\ "swift"
30 / Pcloud
\ "pcloud"
31 / Put.io
\ "putio"
32 / QingCloud Object Storage
\ "qingstor"
33 / SSH/SFTP Connection
\ "sftp"
34 / Sia Decentralized Cloud
\ "sia"
35 / Sugarsync
\ "sugarsync"
36 / Tardigrade Decentralized Cloud Storage
\ "tardigrade"
37 / Transparently chunk/split large files
\ "chunker"
38 / Union merges the contents of several upstream fs
\ "union"
39 / Uptobox
\ "uptobox"
40 / Webdav
\ "webdav"
41 / Yandex Disk
\ "yandex"
42 / Zoho
\ "zoho"
43 / http Connection
\ "http"
44 / premiumize.me
\ "premiumizeme"
45 / seafile
\ "seafile"
Storage> 27
Option client_id.
OAuth Client Id.
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id>
Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>
Option region.
Choose national cloud region for OneDrive.
Enter a string value. Press Enter for the default ("global").
Choose a number from below, or type in your own value.
1 / Microsoft Cloud Global
\ "global"
2 / Microsoft Cloud for US Government
\ "us"
3 / Microsoft Cloud Germany
\ "de"
4 / Azure and Office 365 operated by 21Vianet in China
\ "cn"
region> 1
Edit advanced config?
y) Yes
n) No (default)
y/n>
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> 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 "onedrive"
Then paste the result.
Enter a string value. Press Enter for the default ("").
config_token> {"access_token":"eyJ0eXAiOiJKV1QiLCJuphSlVrWDBfQS1TUktGT2M1MDlDZ3NMV3Q0UGtsNFlKYWNZVVVCWjhuWFkiLCJhbGciOiJSUzI1NiIsLTAwMDAtYzAwMC0wMDAwMDAwMDAwMDAiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC9iZWJmYzdhYS0zY2VlLTQ1ZWUtYjQyZS0wMGEwY2U4OTU1NTYvIiwiaWF0IjoxNjQwMTY3OTM2LCJuYmYiOjE2NDAxNjc51ZDktZWRhNi00MDkyLTg1MzktMGVlYzM3NmFmZDU5IiwiYXBwaWRhY3IiOiIxIiwiZmZWkgUyIsIm9pZCI6IjE0ZmE0MmVlLWZkMmUtNDllZS05MjUxLTA1NTRhMzVjNmEzOSIsInBsYXRmIjoiMyIsInB1aWQiOiIxMDAzMjAwMTczOTA2QzIyIiwicmgiOiIwLkFYRUFxc2VfdnU0ODdrVzBMZ0Nnem9sVlZ0bGxWckdtN1LYjS4eIJF6lOSP7_yXXbbHQQ7dmizN2X_yzuXo3jfwq-0yvUPxz0O6HnOIWOXh430wCgThv6b8WlVHVMmmcT_aYllyabTqU3OHWU_3ZBjJnfWgjavUB9yugHl6PSbHPkCIRw8VPP38BJtWSpDExTf7w3Pquo8NBoQ5nhyzioWa7hf86om4M_plYjRgYMMrzcAUCzyveEGJThmpga37Er6fo5yigZ-j1Y67Tc8H2NhpL7M57bdBo5dPKvhqsrqd7GGtrNetJHK2h6DdXs3D7GsNmX0pdiCVAxcy08g6E6c5MjcyxGvHow4COxWJI7CxzhX85TM-aWTP47pYhsIEAstGkLgNPY_WBF4lXH2KUPozMzDZ0gxGtW7mbTqW_hY7DgvQjuS83J09pud4XMcfO38PE3iLkG6Te2u89h23CVM0WU65io0NE1sg5KsK4_","expiry":"2021-12-22T19:27:51.9462589+08:00"}
Option config_type.
Type of connection
Enter a string value. Press Enter for the default ("onedrive").
Choose a number from below, or type in an existing value.
1 / OneDrive Personal or Business
\ "onedrive"
2 / Root Sharepoint site
\ "sharepoint"
/ Sharepoint site name or URL
3 | E.g. mysite or https://contoso.sharepoint.com/sites/mysite
\ "url"
4 / Search for a Sharepoint site
\ "search"
5 / Type in driveID (advanced)
\ "driveid"
6 / Type in SiteID (advanced)
\ "siteid"
/ Sharepoint server-relative path (advanced)
7 | E.g. /teams/hr
\ "path"
config_type> 3
Option config_site_url.
Site URL
Example: "https://contoso.sharepoint.com/sites/mysite" or "mysite"
Enter a string value. Press Enter for the default ("").
config_site_url> https://contoso.sharepoint.com/sites/myshare
Drive OK?
Found drive "root" of type "documentLibrary"
URL: https://contoso.sharepoint.com/sites/myshare/Shared%20Documents
y) Yes (default)
n) No
y/n>
--------------------
[onedrive5T]
type = onedrive
token = {"access_token":"eyJ0eXAiOiJKV1QiLCJuphSlVrWDBfQS1TUktGT2M1MDlDZ3NMV3Q0UGtsNFlKYWNZVVVCWjhuWFkiLCJhbGciOiJSUzI1NiIsLTAwMDAtYzAwMC0wMDAwMDAwMDAwMDAiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC9iZWJmYzdhYS0zY2VlLTQ1ZWUtYjQyZS0wMGEwY2U4OTU1NTYvIiwiaWF0IjoxNjQwMTY3OTM2LCJuYmYiOjE2NDAxNjc51ZDktZWRhNi00MDkyLTg1MzktMGVlYzM3NmFmZDU5IiwiYXBwaWRhY3IiOiIxIiwiZmZWkgUyIsIm9pZCI6IjE0ZmE0MmVlLWZkMmUtNDllZS05MjUxLTA1NTRhMzVjNmEzOSIsInBsYXRmIjoiMyIsInB1aWQiOiIxMDAzMjAwMTczOTA2QzIyIiwicmgiOiIwLkFYRUFxc2VfdnU0ODdrVzBMZ0Nnem9sVlZ0bGxWckdtN1LYjS4eIJF6lOSP7_yXXbbHQQ7dmizN2X_yzuXo3jfwq-0yvUPxz0O6HnOIWOXh430wCgThv6b8WlVHVMmmcT_aYllyabTqU3OHWU_3ZBjJnfWgjavUB9yugHl6PSbHPkCIRw8VPP38BJtWSpDExTf7w3Pquo8NBoQ5nhyzioWa7hf86om4M_plYjRgYMMrzcAUCzyveEGJThmpga37Er6fo5yigZ-j1Y67Tc8H2NhpL7M57bdBo5dPKvhqsrqd7GGtrNetJHK2h6DdXs3D7GsNmX0pdiCVAxcy08g6E6c5MjcyxGvHow4COxWJI7CxzhX85TM-aWTP47pYhsIEAstGkLgNPY_WBF4lXH2KUPozMzDZ0gxGtW7mbTqW_hY7DgvQjuS83J09pud4XMcfO38PE3iLkG6Te2u89h23CVM0WU65io0NE1sg5KsK4_","expiry":"2021-12-22T19:27:51.9462589+08:00"}
drive_id = 0eXAiOiJKV1QiLCJub25jZSI6InVJck1QemlSb1plblF
drive_type = documentLibrary
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:
Name Type
==== ====
onedrive5T 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>
安装fuse
apt-get install fuse
挂载
#新建本地文件夹,路径自己定,即下面的LocalFolder
mkdir /opt/OneDrive
#挂载为磁盘,下面的DriveName、Folder、LocalFolder参数根据说明自行替换
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
DriveName为初始化配置填的name,Folder为OneDrive里的文件夹,LocalFolder为挂载的本地文件夹。
如我的DriveName:onedrive5T,DriveFolder:/ (挂载总目录),LocalFolder:/opt/OneDrive
rclone mount onedrive5T:/PT /opt/OneDrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
挂载若提示NOTICE: One drive root 'test': poll-interval is not supported by this remote
可以无视。
挂载成功后,输入df -h
查看
卸载:
fusermount -qzu LocalFolder
开机自启
先新建systemd
配置文件,适用CentOS 7
、Debian 8+
、Ubuntu 16+
。
再使用命令:
#将后面修改成你上面手动运行命令中,除了rclone的全部参数
command="mount onedrive5T:/PT /opt/OneDrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000"
#以下是一整条命令,一起复制到SSH客户端运行
cat > /etc/systemd/system/rclone.service <<EOF
[Unit]
Description=Rclone
After=network-online.target
[Service]
Type=simple
ExecStart=$(command -v rclone) ${command}
Restart=on-abort
User=root
[Install]
WantedBy=default.target
EOF
开始启动:
systemctl start rclone
设置开机自启:
systemctl enable rclone
其他命令:
重启:systemctl restart rclone
停止:systemctl stop rclone
状态:systemctl status rclone
如果你想挂载多个网盘,那么将systemd
配置文件的rclone.service
改成rclone1.service
即可,重启动什么的同样换成rclone1
。
复制和同步命令
# 本地到网盘
rclone [功能选项] <本地路径> <网盘名称:路径> [参数] [参数] ...
# 网盘到本地
rclone [功能选项] <网盘名称:路径> <本地路径> [参数] [参数] ...
# 网盘到网盘
rclone [功能选项] <网盘名称:路径> <网盘名称:路径> [参数] [参数] ...
更详细命令:https://www.tok9.com/archives/615/
常用功能
rclone copy
– 复制rclone sync
– 同步 将目录内容同步到网盘目录rclone move
– 移动 将目录内文件移动到网盘,默认删除路径文件rclone purge
– 删除路径及所有文件rclone delete
– 删除路径所有文件但不删除路径rclone mkdir
– 创建目录rclone rmdir
– 删除目录rclone check
– 检查目标文件与源文件是否匹配rclone ls
– 列出指定路径下的所有的文件以及文件大小rclone lsl
– 仅列出对象的修改时间,大小和路径rclone lsd
– 仅列出目录rcloen lsf
– 以易于解析的格式列出对象和目录rcloen lsjson
– 以JSON格式列出对象和目录rclone lsd
– 列出路径下的所有目录rclone size
– 打印目录中对象的总大小和数量rclone mount
– 将远程文件路径挂载到本地路径