前言

网盘对于许多人是必不可少的工具,有人用它同步文件到多个设备,有人用它收集资源。但是公共网盘没有隐私可言,网盘服务商可能会审查你的文件内容,甚至无授权的利用你的数据。当然,你可以自建网盘,但不是所有人都具备这个条件。

本文将告诉你安全使用网盘的一种方法:把网盘当作加密盘使用。这是一篇新手向教程。过程十分简单!

方案介绍

本文的主角是 Rclone,这是我发表的有关 Rclone 的第四篇文章了。它同时提供网盘后端和加密后端两种功能,并且可以搭配使用。将网盘作为存储后端,我想很多人不陌生,因为这是 Rclone 的核心功能。

而加密类型的远程,实际上是一种虚拟后端。它将另一个远程作为后端,在上传前自动加密,下载后自动解密。

在发表文本前,我看到有人为了实现这个需求,推荐了一些并不好用的重型工具搭配着用(例如 Java 编写的 Cryptomator)。这间接推动了我发表本文,因为 Rclone 非常轻量级,且仅使用这一个就可实现所有需求。

其它三篇文章可点击 Rclone 标签链接访问。

基本设置

首先你需要创建一个将云盘作为后端的 Rclone 远程,参考这篇文章。接下来我们基于它创建一个新的远程:

rclone config

Current remotes:

Name Type

==== ====

my-pikpak pikpak

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>n

Enter name for new remote.

name> my-encrypted-pikpak

我们执行 rclone config 命令,并在交互对话中输入 n 后回车。这是创建新远程的基本开头。然后我输入了 my-encrypted-pikpak 作为加密的远程名称。接下来我们进行后续步骤:

Option Storage.

Type of storage to configure.

Choose a number from below, or type in your own value.

13 / Encrypt/Decrypt a remote

\ (crypt)

Storage> 13

Option remote.

Remote to encrypt/decrypt.

Normally should contain a ':' and a path, e.g. "myremote:path/to/dir",

"myremote:bucket" or maybe "myremote:" (not recommended).

Enter a value.

remote> my-pikpak:encrypted

输入编号选择 Encrypt/Decrypt a remote,不同版本下编号可能也不同,我这边是 13。接着输入 my-pikpak:encrypted 作为后端远程。注意这里的 my-pikpak 是一个存在的,已创建好的远程。后半部分是路径,可以是子路径。目录会自动创建(此处的目录是 /encrypted)。

再然后是加/解密的设置:

Option filename_encryption.

How to encrypt the filenames.

Choose a number from below, or type in your own string value.

Press Enter for the default (standard).

/ Encrypt the filenames.

1 | See the docs for the details.

\ (standard)

2 / Very simple filename obfuscation.

\ (obfuscate)

/ Don't encrypt the file names.

3 | Adds a ".bin", or "suffix" extension only.

\ (off)

filename_encryption> 3

Option directory_name_encryption.

Option to either encrypt directory names or leave them intact.

NB If filename_encryption is "off" then this option will do nothing.

Choose a number from below, or type in your own boolean value (true or false).

Press Enter for the default (true).

1 / Encrypt directory names.

\ (true)

2 / Don't encrypt directory names, leave them intact.

\ (false)

directory_name_encryption> 2

以上步骤选择的是:不加密文件名、不加密目录名。默认(直接回车)的话两个都是加密或混淆的,意思就是我如果登录 PikPak 官方的客户端或网页,看到的是一堆不知含义的目录和文件名。我个人没有这样的需求,所以都选择不加密。

上述步骤提到的加密是指的云盘中的原始文件名和目录名,它和文件是否加密没有关系。只是名称。

最后是密码设置:

Option password.

Password or pass phrase for encryption.

Choose an alternative below.

y) Yes, type in my own password

g) Generate random password

y/g> g

Password strength in bits.

64 is just about memorable

128 is secure

1024 is the maximum

Bits> 64

Your password is: xxxxxxxxxxxx

Use this password? Please note that an obscured version of this

password (and not the password itself) will be stored under your

configuration file, so keep this generated password in a safe place.

y) Yes (default)

n) No

y/n>

Option password2.

Password or pass phrase for salt.

Optional but recommended.

Should be different to the previous password.

Choose an alternative below. Press Enter for the default (n).

y) Yes, type in my own password

g) Generate random password

n) No, leave this optional password blank (default)

y/g/n> g

Password strength in bits.

64 is just about memorable

128 is secure

1024 is the maximum

Bits> 64

Your password is: xxxxxxxxxxxx

Use this password? Please note that an obscured version of this

password (and not the password itself) will be stored under your

configuration file, so keep this generated password in a safe place.

y) Yes (default)

n) No

y/n

上述步骤中,我生成了 64 字节的两个随机密码。第一个密码用于加密,第二个密码用于盐。你也可以选择自己输入密码(Yes, type in my own password 选项),并且第二个密码可以留空。如果选择随机生成,终端会输出你的密码(Your password is: 后面的部分,我在这里用 xxxxxxxxxxxx 替代),记得保存好。

此处的密码和网盘或 WebDAV 的访问没有关系,即使泄漏危害也不会太大。但如果丢失的话,在没有 Rclone 现存的配置的情况下,你就无法恢复云盘文件了。

必要的设置到这里已经完成了,后面直接回车即可:

Edit advanced config?

y) Yes

n) No (default)

y/n>

Configuration complete.

Options:

- type: crypt

- remote: my-pikpak:encrypted

- filename_encryption: off

- directory_name_encryption: false

- password: *** ENCRYPTED ***

- password2: *** ENCRYPTED ***

Keep this "my-encrypted-pikpak" remote?

y) Yes this is OK (default)

e) Edit this remote

d) Delete this remote

y/e/d>

Current remotes:

Name Type

==== ====

my-encrypted-pikpak crypt

my-pikpak pikpak

e) Edit existing remote

n) New remote

d) Delete remote

r) Rename remote

c) Copy remote

s) Set configuration password

q) Quit config

询问是否编辑高级配置,回车否掉。然后询问是否 Ok,回车确认。最后一个输出会列出最新的远程列表,可以看到我们的 my-encrypted-pikpak 已经创建好了,类型是 crypt。

WebDAV

参考这篇文章,我们将 my-encrypted-pikpak 作为后端启动 WebDAV 即可。

使用

将该 WebDAV 服务挂载到本地目录,就像一个普通的目录那样操作它:

从以上截图可以看到,在文件管理器中文件以原始名称显示,但在 PikPak 的网页中文件多了 .bin 后缀。这是因为当我们访问文件时 Rclone 自动为我们执行了解密操作,而复制进去的文件又会被自动加密上传。

也就是说,加/解密过程对于用户而言完全是透明的。我们只需要将它视作一个普通的 PikPak 后端即可。

结束语

这就是 Rclone 的加密功能和 WebDAV 搭配使用的教程了。按照这个步骤,我们可以将网盘作为加密盘,无感知的使用。同时我们的文件对于网盘服务商来说是加密的,它无法审查我们的内容。而且我们的文件对于服务商没有任何价值,杜绝了非法利用的可能性。

这就是我一直在用的方法,希望对你有所帮助。