Rcloneでクラウドストレージのデータを圧縮・暗号化する
Rcloneという、多数のクラウドストレージに対応したファイル管理ソフトウェアがあります。
日本時間2025年11月22日、そんなRcloneのv1.72がリリースされ、Zstandardによる圧縮機能が追加されました。以前からGzipでの圧縮は可能でしたが、Zstandardに対応したことで、より高い圧縮率でクラウドストレージにデータを詰め込めるようになりました。
Rcloneにはデータの暗号化機能も備わっており、この二つを組み合わせることによってクラウドストレージをプライベートなNASのような感覚で使用することができます。この記事は、(簡単なものではありますが)そのセットアップガイドです。
やりかた
Step 0: Rcloneのインストール
公式のインストールガイドを参考にどうぞ。
Step 1: クラウドストレージに接続
以下のコマンドからインタラクティブな設定画面を開きます。
rclone config
No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
n を押し、適当な名前を入力して続行します(ここでは“drive”としましょう)。
name> drive
対応しているクラウドドライブサービスの一覧が表示されるので、使用したいものを選び入力してください。その後、ダイアログに従い設定を完了します。
Step 2: 暗号化を設定
クラウドストレージの設定が完了すると以下の画面に戻ってくるはずです。
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
そうしたら、再びn を押し、適当な名前を入れます(ここでは“crypt”としましょう)。
name> crypt
今度はサービスとして“crypt”を選択します。
crypt> crypt
ここで、お使いのクラウドストレージ上に適当なフォルダを作成しておきます。名前は何でもよいですが、ここではCryptとします。
“remote”オプションには、Step1でつけた名前のあとに:をつけ、先ほど作成したフォルダを指定します。
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> drive:Crypt
以下二つの設定はデフォルトでOKです。
Option filename_encryption.
How to encrypt the filenames.
Choose a number from below, or type in your own value of type string.
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>
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>
パスワードの設定です。自分で設定する場合y、ランダム生成する場合gを入力します。ここではランダム生成を選びます。
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
パスワードの長さの設定です。ここでは最大の1024を選びます。
Password strength in bits.
64 is just about memorable
128 is secure
1024 is the maximum
Bits> 1024
生成されました。再設定する場合や、他のPCで設定する場合などに必要になるので、大切に保管しましょう。失くしてしまうと復旧できなくなります。
Your password is: [ここにパスワードが表示されます]
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> y
パスワードを二段掛けにする設定です。設定しなくてもOKですが、設定することが推奨されています。設定しない場合は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> 1024
Your password is: [ここにパスワードが表示されます]
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> y
高度な設定です。基本的にはデフォルトでよいのですが、2つだけ変更する価値のある設定があるのでyで入ります。
Edit advanced config?
y) Yes
n) No (default)
y/n> y
以下の4設定はデフォルトのままで問題ありません。Enterキーで飛ばしてください。
Option server_side_across_configs.
Deprecated: use --server-side-across-configs instead.
Allow server-side operations (e.g. copy) to work across different crypt configs.
Normally this option is not what you want, but if you have two crypts
pointing to the same backend you can use it.
This can be used, for example, to change file name encryption type
without re-uploading all the data. Just make two crypt backends
pointing to two different directories with the single changed
parameter and use rclone move to move the files between the crypt
remotes.
Enter a boolean value (true or false). Press Enter for the default (false).
server_side_across_configs>
Option no_data_encryption.
Option to either encrypt file data or leave it unencrypted.
Choose a number from below, or type in your own boolean value (true or false).
Press Enter for the default (false).
1 / Don't encrypt file data, leave it unencrypted.
\ (true)
2 / Encrypt file data.
\ (false)
no_data_encryption>
Option pass_bad_blocks.
If set this will pass bad blocks through as all 0.
This should not be set in normal operation, it should only be set if
trying to recover an encrypted file with errors and it is desired to
recover as much of the file as possible.
Enter a boolean value (true or false). Press Enter for the default (false).
pass_bad_blocks>
Option strict_names.
If set, this will raise an error when crypt comes across a filename that can't be decrypted.
(By default, rclone will just log a NOTICE and continue as normal.)
This can happen if encrypted and unencrypted files are stored in the same
directory (which is not recommended.) It may also indicate a more serious
problem that should be investigated.
Enter a boolean value (true or false). Press Enter for the default (false).
strict_names>
変更する価値のある設定その1です。デフォルト設定ではファイル名を暗号化したのちBase32でエンコードしますが、これだとファイル名がかなり長くなってしまいます。クラウドストレージがアルファベットの大文字と小文字を区別するような設計になっていれば、Base64でエンコードすることでファイル名を削減することができます。クラウドストレージ上の同じフォルダ内に“test.txt”と“TEST.txt”を作成してみて、共存できるようならばBase64を選ぶとよいです。
Base32768というオプションもありますが、こちらはクラウドストレージが対応しているか簡単に判断する方法がなさそうなので選ばないのが安全でしょう。対応している例として挙げられている、OneDriveとDropboxでは選択してよいでしょう。
Option filename_encoding.
How to encode the encrypted filename to text string.
This option could help with shortening the encrypted filename. The
suitable option would depend on the way your remote count the filename
length and if it's case sensitive.
Choose a number from below, or type in your own value of type string.
Press Enter for the default (base32).
1 / Encode using base32. Suitable for all remote.
\ (base32)
2 / Encode using base64. Suitable for case sensitive remote.
\ (base64)
/ Encode using base32768. Suitable if your remote counts UTF-16 or
3 | Unicode codepoint instead of UTF-8 byte length. (Eg. Onedrive, Dropbox)
\ (base32768)
filename_encoding> base64
変更する価値のある設定その2です。デフォルトでは暗号化されたファイル名に.binという拡張子が付加されますが、どうせそのままでは読み取れないので拡張子はなくしてしまった方がファイル名の短縮になります。noneと入力することで、拡張子をなくすことができます。
Option suffix.
If this is set it will override the default suffix of ".bin".
Setting suffix to "none" will result in an empty suffix. This may be useful
when the path length is critical.
Enter a value of type string. Press Enter for the default (.bin).
suffix> none
あとはデフォルトでOKです。
Option description.
Description of the remote.
Enter a value. Press Enter to leave empty.
description>
この画面に戻ってくるので、n
Edit advanced config?
y) Yes
n) No (default)
y/n> n
その後、y で保存します。
Keep this "crypt" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
Step 3: 圧縮を設定
再びこの画面に帰ってくるはずです。
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
またnを押し、適当な名前を入れます(ここでは“compress”とします)。
name> compress
今度はサービスとしてcompressを選びます。
compress> compress
“remote”オプションには、Step2でつけた名前のあとに:をつけたものを指定します。
Option remote.
Remote to compress.
Enter a value.
remote> crypt:
ここがこの記事のメインテーマです。Rclone 1.72で新しく追加されたZstandardを選びましょう。
Option mode.
Compression mode.
Choose a number from below, or type in your own value of type string.
Press Enter for the default (gzip).
1 / Standard gzip compression with fastest parameters.
\ (gzip)
2 / Zstandard compression — fast modern algorithm offering adjustable speed-to-compression tradeoffs.
\ (zstd)
mode> zstd
圧縮設定です。Zstandardを選んだので、下の方のリストを見ます。0で圧縮無効、1から4にかけて圧縮率が高くなりますがCPU使用率も上がります。2がデフォルトです。お好みで設定しましょう。ここでは最大の4を選んでみます。
Option level.
GZIP (levels -2 to 9):
- -2 — Huffman encoding only. Only use if you know what you're doing.
- -1 (default) — recommended; equivalent to level 5.
- 0 — turns off compression.
- 1–9 — increase compression at the cost of speed. Going past 6 generally offers very little return.
ZSTD (levels 0 to 4):
- 0 — turns off compression entirely.
- 1 — fastest compression with the lowest ratio.
- 2 (default) — good balance of speed and compression.
- 3 — better compression, but uses about 2–3x more CPU than the default.
- 4 — best possible compression ratio (highest CPU cost).
Notes:
- Choose GZIP for wide compatibility; ZSTD for better speed/ratio tradeoffs.
- Negative gzip levels: -2 = Huffman-only, -1 = default (≈ level 5).
Enter a value.
level> 4
今度は高度な設定にめぼしいものはないので、nでデフォルトのまま続行します。
Edit advanced config?
y) Yes
n) No (default)
y/n> n
yで保存します。
Keep this "compress" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
この画面に帰ってくるので、qで終了します。
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
これで設定は完了です。あとは、このステップで作成したリモートに対しrclone mountコマンドなどを使用すれば、普通のクラウドストレージと同じ感覚で使用することができます。この部分のセットアップについては他所をご参照ください。
動作チェック
ddコマンドで、ゼロ埋めされた10GiBのファイルを作成してみます。
% dd if=/dev/zero of=./test/sample.bin bs=1G count=10 status=progress
10737418240 bytes (11 GB, 10 GiB) transferred 63.140s, 170 MB/s
10+0 records in
10+0 records out
lsしてみると、きちんと10GiBあります。
% ls -alh test
total 20971520
drwxr-xr-x 1 syobon staff 0B 11月 22 17:12 ./
drwxr-xr-x 1 syobon staff 0B 11月 22 17:09 ../
-rw-r--r-- 1 syobon staff 10G 11月 22 17:11 sample.bin
今度はクラウドストレージ上にある、実体ファイルを見にいってみます。
% ls -alh luzsBoIbjheTgv3R2v5g_g
total 24129
drwxr-xr-x 1 syobon staff 0B 11月 22 17:12 ./
drwxr-xr-x 1 syobon staff 0B 11月 22 17:09 ../
-rw-r--r-- 1 syobon staff 8.4M 11月 22 17:11 0tWE7h-hFMOWhyqeJ9lBL9mNTUWK-DnQwY5aQk4EpWs
-rw-r--r-- 1 syobon staff 3.3M 11月 22 17:11 Nv1Z6PQNnls27WebG1vzTg
きちんとファイル名も暗号化されており、ファイルサイズも大きく減少しているのがわかります。
ちなみに、8.4MiBの方がファイルの実体で、となりにある3.3MiBのファイルは圧縮の際に作成されるJSON形式のメタデータです。
メタデータの方をheadコマンドで覗いてみると以下のようになっており、きちんと暗号化されているのがわかります。
% head -c 1000 luzsBoIbjheTgv3R2v5g_g/Nv1Z6PQNnls27WebG1vzTg
???ֆI?k?? V?װ??`????O=L
f?C~`?מ?j??
?8???j???%ӱr??kp??^AQ/?ωCɰm?W?b??~K]I ?.???K|?~????<?t?p[??ll?t?M5f,??f??????""+ϔ%?=H??=????
?L?9"?ƺٻy ̯?g?U
??-??wS?9ʨ)H??ޝy??L\??A?פ????????1??5?? V+1}?^Ѣ?,?_????_Gv??F??t_tP?z?=4?C??^k?E????تy??v?"?<R]3?I??r{???4ߪ/???=N?x?$yt_??6*?D?}?e???HĵhxB??rS
????ܱ?b2?L^+*M4??b??<??.s??n]?,??^?!'?2CM????ZXD?F??ޤ?V?Q????$.?F?tI9=???'??T%o?P/,yt=?8????̪0#^QR7Ҹ??RJ?Gne?-?t???Y)
%??j?a0????=/>?⋄?8c`"M??1R??i??Ze?wgF?*?8??a??"O%Q?M/?n??:R?b??
uh?!*?L???sv?r???N??Q????&;?۟Քj?tx?6?톂I?rXP?|LW?\????hWz??m??9hDeY?dk?Li1????S䭙F???WCFw??w?q3>?D?'??L?V?????]6?VP???eb?*?$??p[?7:??~K?!2h
?W?p?????)?]9Ő?? ?>]$!?]?^?)?+
??خc??H????0T&?]?mu
?~?1?%?Y??ʺ\?Go[:K?{;????ӫ?=WT/>-?~Aqz5?????.?җ?O/,?>?|?~?M>??~#??r?|r????Rw?MY??wݵ?? ?i?Z?"ȵ..$?=v?(0??
jS _?ⵛ????l>d.5??|????⏎
注意
必ず「クラウドストレージ ← crypt ← compress」の順になるように設定してください。
誤って「クラウドストレージ ← compress ← crypt」としてしまうと、暗号化によってランダムデータと区別が付かなくなったデータに対し圧縮をかけることになり、圧縮の効果が得られません。