1. 获取Token

在Windows电脑上下载Rclone,下载地址:> https://rclone.org/downloads/,然后解压,使用cmd进入解压后的文件夹:

rclone.exe authorize "onedrive"

ps:整个大括号就是token,包括大括号。

2.在Linux上安装Rclone

直接使用官方提供的一键脚本:

curl https://rclone.org/install.sh | bash

3.配置

安装完成后执行:

rclone config
    rclone config
    2021/03/03 15:00:17 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> n
    name> onedrive
    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, and Tencent COS
       \ "s3"
     5 / Backblaze B2
       \ "b2"
     6 / Box
       \ "box"
     7 / Cache a remote
       \ "cache"
     8 / Citrix Sharefile
       \ "sharefile"
     9 / Compress a remote
       \ "compress"
    10 / Dropbox
       \ "dropbox"
    11 / Encrypt/Decrypt a remote
       \ "crypt"
    12 / Enterprise File Fabric
       \ "filefabric"
    13 / FTP Connection
       \ "ftp"
    14 / Google Cloud Storage (this is not Google Drive)
       \ "google cloud storage"
    15 / Google Drive
       \ "drive"
    16 / Google Photos
       \ "google photos"
    17 / Hadoop distributed file system
       \ "hdfs"
    18 / Hubic
       \ "hubic"
    19 / In memory object storage system.
       \ "memory"
    20 / Jottacloud
       \ "jottacloud"
    21 / Koofr
       \ "koofr"
    22 / Local Disk
       \ "local"
    23 / Mail.ru Cloud
       \ "mailru"
    24 / Mega
       \ "mega"
    25 / Microsoft Azure Blob Storage
       \ "azureblob"
    26 / Microsoft OneDrive
       \ "onedrive"
    27 / OpenDrive
       \ "opendrive"
    28 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
       \ "swift"
    29 / Pcloud
       \ "pcloud"
    30 / Put.io
       \ "putio"
    31 / QingCloud Object Storage
       \ "qingstor"
    32 / SSH/SFTP Connection
       \ "sftp"
    33 / Sugarsync
       \ "sugarsync"
    34 / Tardigrade Decentralized Cloud Storage
       \ "tardigrade"
    35 / Transparently chunk/split large files
       \ "chunker"
    36 / Union merges the contents of several upstream fs
       \ "union"
    37 / Webdav
       \ "webdav"
    38 / Yandex Disk
       \ "yandex"
    39 / Zoho
       \ "zoho"
    40 / http Connection
       \ "http"
    41 / premiumize.me
       \ "premiumizeme"
    42 / seafile
       \ "seafile"
    Storage> 26
    ** See help for onedrive backend at: https://rclone.org/onedrive/ **
    
    OAuth Client Id
    Leave blank normally.
    Enter a string value. Press Enter for the default ("").
    client_id> 
    OAuth Client Secret
    Leave blank normally.
    Enter a string value. Press Enter for the default ("").
    client_secret> 
    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/n)
    y) Yes
    n) No (default)
    y/n> n
    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> n
    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 below:
    result> {"access_token":qqqqqqqqqq","expiry":"2021-03-03T15:54:34.7442912+08:00"}  
    token
    Choose a number from below, or type in an existing value
     1 / OneDrive Personal or Business
       \ "onedrive"
     2 / Root Sharepoint site
       \ "sharepoint"
     3 / Sharepoint site name or URL (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"
     7 / Sharepoint server-relative path (advanced, e.g. /teams/hr)
       \ "path"
    Your choice> 1
    Found 1 drives, please select the one you want to use:
    0: OneDrive (business) id=b!B6yHyawk7kq599Kb4wYXQFe1jafkFoFBqrwS7ZFYLJsUbhule-g-Rax7IpAhk6c8
    Chose drive to use:> 0
    Found drive 'root' of type 'business', URL: https://imissyou5201314-my.sharepoint.com/personal/codehero_imissyou5201314_onmicrosoft_com/Documents
    Is that okay?
    y) Yes (default)
    n) No
    y/n>y
    --------------------
    [onedrive]
    type = onedrive
    region = global
    token = {"access_token":"O2bSfUr74YzUssTNQqL2bUzCbxlZMNHa5OEdJwZuOXPfv6IdCdk_E1jWMmjxHNIi7NLZ6GWqaOUARsqq_5JLTDEpo6F5VS5vbTOOVuDP3MhAcvL9aSXBk7BKxXu6yMoZp7uaynmCESg4ADFEFSSefwefwefsefwfgsalkfhsehjfg2bewo_EASPdtlIkjW0v5lCliU1cXxuPGZ_Lq1eOYyjPLMvAJ9pMiKg2-Iw1-844H67E0V9FCY8cBzH3qSui8rgQwt9nBI2PI0uaJ6KlVpQb0IiTQGapw2hgubwprnSVM39B5Z58WUon2ObcJ76CP7VPMvxIFIVnP5oq2gi1PRTxPgN3z64z3Q1hbwM59HqOrwX84uWIvCk63_i6ocVb0nasiY7EaLoF9fJHAnAw2qC3dOng","expiry":"2021-03-03T15:54:34.7442912+08:00"}drive_id = b!B6yHyawk7kq599Kb4wYXQFe1jafkFoFBqrwS7ZFYLJsUbhule-g-Rax7IpAhk6c8
    drive_type=business
    --------------------
    y) Yes this is OK (default)
    e) Edit this remote
    d) Delete this remote
    y/e/d> y
    Current remotes:
    
    Name                 Type
    ====                 ====
    onedrive             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
    e/n/d/r/c/s/q>

4.安装fuse

apt install fuse3

5.挂载OneDrive

-新建挂载目录

mkdir /mnt/onedrive

-挂载
挂载为磁盘,下面的DriveName、Folder、LocalFolder参数根据说明自行替换
--daemon为守护进程参数

rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

我的命令为,如果想指定onedrive下的某个目录修改Folder

rclone mount onedrive:/ /mnt/onedrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

-再开一个SSH窗口,执行:df -h 查看是否挂载成功。

6.开机自启

在/etc/systemed/system/目录下创建rclone.service
内容如下:

[Unit]
Description=Rclone
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/rclone  mount onedrive:/ /mnt/onedrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
KillModel=process
Restart=on-abort
User=root

[Install]
WantedBy=default.target

之后就可以使用 systemctl来挂载了:

  • 开机自启

    systemctl enable rclone
  • 启动

    systemctl start rclone
  • 重启

    systemctl restart  rclone
  • 停止

    systemctl status rclone

7.复制和同步命令

  • 本地上传到网盘
    r clone [指令名称] [本地路径] [网盘名称:网盘路径] [flags] [flags]
  • 网盘下载到本地
    rclone [指令名称] [网盘名称:网盘路径] [本地路径] [flags]
  • 网盘上传/下载到网盘
    rclone [指令名称] [网盘名称:网盘路径] [网盘名称:网盘路径] [flags] [flags]
  • 显示速度 -v
  • 指令copy sync

8.常用指令

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 – 将远程文件路径挂载到本地路径