Skip to content

Commit b67c703

Browse files
authored
Merge pull request #14560 from nextcloud/docs/admin-occ-encryption-completeness
docs(admin): add occ_encryption.rst with complete encryption command docs
2 parents db9f4de + ca6ad1e commit b67c703

3 files changed

Lines changed: 366 additions & 99 deletions

File tree

admin_manual/occ_command.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Command reference
207207

208208
occ_apps
209209
occ_database
210+
occ_encryption
210211
occ_files
211212
occ_ldap
212213
occ_users

admin_manual/occ_encryption.rst

Lines changed: 360 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,360 @@
1+
.. _encryption_label:
2+
3+
====================
4+
Encryption commands
5+
====================
6+
7+
The ``encryption`` commands manage server-side encryption, encryption keys, and
8+
encryption modules. The core commands are always available. Commands that
9+
operate on the encryption module itself (master key, key repair, legacy
10+
migration) require the **Encryption** app (``encryption``) to be enabled.
11+
12+
.. note::
13+
14+
For a full guide to configuring server-side encryption, see
15+
:doc:`../configuration_files/encryption_configuration`.
16+
17+
::
18+
19+
encryption
20+
encryption:change-key-storage-root change key storage root
21+
encryption:clean-orphaned-keys scan the keys storage for orphaned keys and remove them
22+
encryption:decrypt-all disable server-side encryption and decrypt all files
23+
encryption:disable disable encryption
24+
encryption:disable-master-key disable the master key and use per-user keys instead
25+
encryption:drop-legacy-filekey scan the files for the legacy filekey format using RC4 and get rid of it
26+
encryption:enable enable encryption
27+
encryption:enable-master-key enable the master key
28+
encryption:encrypt-all encrypt all files for all users
29+
encryption:fix-encrypted-version fix the encrypted version if the encrypted file(s) are not downloadable
30+
encryption:fix-key-location fix the location of encryption keys for external storage
31+
encryption:list-modules list all available encryption modules
32+
encryption:migrate-key-storage-format migrate the format of the key storage to a newer format
33+
encryption:recover-user recover user data in case of password loss
34+
encryption:scan:legacy-format scan the files for the legacy format
35+
encryption:set-default-module set the encryption default module
36+
encryption:show-key-storage-root show current key storage root
37+
encryption:status lists the current status of encryption
38+
39+
40+
Status and control
41+
------------------
42+
43+
encryption\:status
44+
""""""""""""""""""
45+
46+
Show whether encryption is enabled and which module is active::
47+
48+
sudo -E -u www-data php occ encryption:status
49+
- enabled: false
50+
- defaultModule: OC_DEFAULT_MODULE
51+
52+
Use ``--output=json_pretty`` for machine-readable output.
53+
54+
encryption\:enable
55+
""""""""""""""""""
56+
57+
Enable server-side encryption. The **Encryption** app must be enabled first and
58+
a default module must be configured::
59+
60+
sudo -E -u www-data php occ app:enable encryption
61+
sudo -E -u www-data php occ encryption:enable
62+
Encryption enabled
63+
64+
Default module: OC_DEFAULT_MODULE
65+
66+
encryption\:disable
67+
"""""""""""""""""""
68+
69+
Disable server-side encryption. This only disables the encryption flag — it
70+
does not decrypt any files::
71+
72+
sudo -E -u www-data php occ encryption:disable
73+
Encryption disabled
74+
75+
To also decrypt all existing files, run
76+
``encryption:decrypt-all`` afterwards.
77+
78+
79+
Encrypt and decrypt all data
80+
-----------------------------
81+
82+
encryption\:encrypt-all
83+
""""""""""""""""""""""""
84+
85+
Encrypt all files for all users. Encryption must be enabled before running
86+
this command. The command manages maintenance mode internally — do **not**
87+
enable maintenance mode first, as the command will fail if it is already
88+
active::
89+
90+
sudo -E -u www-data php occ encryption:encrypt-all
91+
You are about to encrypt all files stored in your Nextcloud installation.
92+
Depending on the number of available files, and their size, this may take quite some time.
93+
Please ensure that no user accesses their files during this time!
94+
Note: The encryption module you use determines which files get encrypted.
95+
96+
Do you really want to continue? (y/n)
97+
98+
The command requires an interactive terminal (TTY). If running inside a
99+
Docker container, use ``docker exec -it``.
100+
101+
encryption\:decrypt-all
102+
""""""""""""""""""""""""
103+
104+
Decrypt all files for all users, or for a single user. The command manages
105+
maintenance mode internally — do **not** enable maintenance mode first::
106+
107+
sudo -E -u www-data php occ encryption:decrypt-all
108+
sudo -E -u www-data php occ encryption:decrypt-all layla
109+
110+
When decrypting all users, server-side encryption is disabled automatically.
111+
When decrypting a single user, encryption remains enabled for others.
112+
113+
Depending on the encryption module in use, decryption may require:
114+
115+
* **Master key mode** — no extra credentials needed.
116+
* **Per-user key mode** — the user must have enabled the recovery key on their
117+
personal settings page.
118+
119+
The command requires an interactive terminal (TTY). If running inside a
120+
Docker container, use ``docker exec -it``.
121+
122+
123+
Encryption modules
124+
------------------
125+
126+
encryption\:list-modules
127+
"""""""""""""""""""""""""
128+
129+
List all available encryption modules. The active default module is marked
130+
with ``[default*]``::
131+
132+
sudo -E -u www-data php occ encryption:list-modules
133+
- OC_DEFAULT_MODULE: Default encryption module [default*]
134+
135+
encryption\:set-default-module
136+
"""""""""""""""""""""""""""""""
137+
138+
Set the default encryption module. Maintenance mode must be disabled::
139+
140+
sudo -E -u www-data php occ encryption:set-default-module OC_DEFAULT_MODULE
141+
Set default module to "OC_DEFAULT_MODULE"
142+
143+
144+
Key storage
145+
-----------
146+
147+
encryption\:show-key-storage-root
148+
""""""""""""""""""""""""""""""""""
149+
150+
Show where encryption keys are stored::
151+
152+
sudo -E -u www-data php occ encryption:show-key-storage-root
153+
Current key storage root: default storage location (data/)
154+
155+
encryption\:change-key-storage-root
156+
"""""""""""""""""""""""""""""""""""""
157+
158+
Move encryption keys to a different directory. The target directory must exist
159+
and be writable by the web server user before running the command::
160+
161+
sudo -E -u www-data php occ encryption:change-key-storage-root /etc/nextcloud/keys
162+
Change key storage root from default storage location to /etc/nextcloud/keys
163+
Start to move keys:
164+
[============================]
165+
Key storage root successfully changed to /etc/nextcloud/keys
166+
167+
Omit the argument to reset the key storage root back to the default
168+
location (``data/``). The command will ask for confirmation::
169+
170+
sudo -E -u www-data php occ encryption:change-key-storage-root
171+
No storage root given, do you want to reset the key storage root to the default location? (y/n)
172+
173+
encryption\:migrate-key-storage-format
174+
""""""""""""""""""""""""""""""""""""""""
175+
176+
Migrate the key storage to the current format (JSON-wrapped, re-encrypted with
177+
the server secret). Run this once after upgrading from an installation that
178+
used the legacy key format::
179+
180+
sudo -E -u www-data php occ encryption:migrate-key-storage-format
181+
Updating key storage format
182+
Start to update the keys:
183+
[============================]
184+
Key storage format successfully updated
185+
186+
187+
Master key
188+
----------
189+
190+
The master key encrypts all user data with a single server-managed key. It is
191+
the recommended setup for new installations because it simplifies key
192+
management and enables admin-side decryption without per-user passwords. The
193+
master key is enabled by default when the Encryption app is first enabled.
194+
195+
Both commands are only available when the **Encryption** app is enabled.
196+
197+
.. warning::
198+
199+
Switching between master key and per-user key mode is only safe on a
200+
**fresh installation with no existing encrypted data**. If you switch modes
201+
on an instance that already has encrypted files, those files will become
202+
permanently inaccessible: the new mode looks for keys that were never
203+
created for the existing data. **There is no recovery path.** Always run
204+
``encryption:decrypt-all`` first if you need to change modes on an existing
205+
installation.
206+
207+
.. note::
208+
209+
Despite the warning shown by both commands ("no way to enable/disable it
210+
again"), the switch is technically reversible as long as no encrypted data
211+
exists yet. The warning is intended to convey that you cannot safely switch
212+
modes once users have data.
213+
214+
encryption\:enable-master-key
215+
"""""""""""""""""""""""""""""""
216+
217+
Enable the master key. Only use this on a **fresh installation with no
218+
existing encrypted data**. The command prompts for confirmation::
219+
220+
sudo -E -u www-data php occ encryption:enable-master-key
221+
Master key successfully enabled.
222+
223+
encryption\:disable-master-key
224+
""""""""""""""""""""""""""""""""
225+
226+
Disable the master key and revert to per-user keys. Only use this on a
227+
**fresh installation with no existing encrypted data**. The command prompts
228+
for confirmation::
229+
230+
sudo -E -u www-data php occ encryption:disable-master-key
231+
Master key successfully disabled.
232+
233+
Switching to per-user keys has the following consequences:
234+
235+
* **Performance** — per-user key operations are slower. Each user's key must
236+
be derived individually on every file access.
237+
* **Password loss means data loss** — without the master key there is no
238+
admin-side decryption path. Each user must enable the recovery key on their
239+
personal settings page *before* losing their password. Without it,
240+
``encryption:recover-user`` cannot help and the files cannot be recovered.
241+
* **Admin decryption is no longer possible** — admins cannot decrypt or access
242+
a user's files without that user's password or a pre-set recovery key.
243+
244+
245+
Maintenance and repair
246+
-----------------------
247+
248+
encryption\:clean-orphaned-keys
249+
"""""""""""""""""""""""""""""""""
250+
251+
Scan the key storage for keys that no longer have a corresponding file and
252+
remove them. Optionally limit the scan to a single user::
253+
254+
sudo -E -u www-data php occ encryption:clean-orphaned-keys
255+
sudo -E -u www-data php occ encryption:clean-orphaned-keys layla
256+
257+
When orphaned keys are found, the command lists them and asks interactively
258+
whether to delete all, specific ones, or none::
259+
260+
sudo -E -u www-data php occ encryption:clean-orphaned-keys layla
261+
Key storage scan for layla
262+
==========================
263+
264+
Orphaned key found: /layla/files_encryption/keys/files/old-doc.pdf/OC_DEFAULT_MODULE/fileKey
265+
Do you want to delete all orphaned keys? (y/n)
266+
267+
If no orphaned keys are found, the command exits silently.
268+
269+
encryption\:fix-encrypted-version
270+
"""""""""""""""""""""""""""""""""""
271+
272+
Fix the encrypted version counter in the file cache when encrypted files
273+
cannot be downloaded. Requires **master key** encryption.
274+
275+
Run for a single user::
276+
277+
sudo -E -u www-data php occ encryption:fix-encrypted-version layla
278+
Verifying the content of file "/layla/files/Documents/report.pdf"
279+
The file "/layla/files/Documents/report.pdf" is: OK
280+
281+
Run for all users::
282+
283+
sudo -E -u www-data php occ encryption:fix-encrypted-version --all
284+
Processing files for layla
285+
Verifying the content of file "/layla/files/Documents/report.pdf"
286+
The file "/layla/files/Documents/report.pdf" is: OK
287+
288+
When a broken file is found, the command tries decrementing and then
289+
incrementing the encrypted version counter until the file can be read::
290+
291+
Attempting to fix the path: "/layla/files/Documents/broken.pdf"
292+
Decrement the encrypted version to 2
293+
Fixed the file: "/layla/files/Documents/broken.pdf" with version 2
294+
295+
Use ``-p`` / ``--path`` to limit the scan to a specific directory::
296+
297+
sudo -E -u www-data php occ encryption:fix-encrypted-version layla --path="/Documents"
298+
299+
encryption\:fix-key-location
300+
""""""""""""""""""""""""""""""
301+
302+
Fix the location of encryption keys for files on external storage mounts. Run
303+
this when users cannot access files on external storage after a migration::
304+
305+
sudo -E -u www-data php occ encryption:fix-key-location layla
306+
Migrating key for /layla/files/ExternalDrive/report.pdf ✓
307+
308+
Use ``--dry-run`` to list files that need migration without making any
309+
changes::
310+
311+
sudo -E -u www-data php occ encryption:fix-key-location --dry-run layla
312+
/layla/files/ExternalDrive/report.pdf needs migration
313+
314+
encryption\:recover-user
315+
"""""""""""""""""""""""""
316+
317+
Recover a user's files after a password loss. Only available in **per-user
318+
key** mode (not applicable when master key is enabled). The user must have
319+
enabled the recovery key in their personal settings before the password was
320+
lost.
321+
322+
The command prompts for the recovery key password and the new login password::
323+
324+
sudo -E -u www-data php occ encryption:recover-user layla
325+
Please enter the recovery key password:
326+
Please enter the new login password for the user:
327+
Start to recover users files... This can take some time...Done.
328+
329+
330+
Legacy migration
331+
----------------
332+
333+
encryption\:drop-legacy-filekey
334+
"""""""""""""""""""""""""""""""""
335+
336+
Scan all files for the legacy RC4 filekey format and migrate them to the
337+
current format. Requires **master key** encryption. Files not migrated by this
338+
command will be migrated automatically on their next write. Running this
339+
command upfront also converts old base64-encoded files to binary format,
340+
saving approximately 33% disk space::
341+
342+
sudo -E -u www-data php occ encryption:drop-legacy-filekey
343+
Scanning all files for legacy filekey
344+
Scanning all files for layla
345+
All scanned files are properly encrypted.
346+
347+
encryption\:scan\:legacy-format
348+
""""""""""""""""""""""""""""""""
349+
350+
Scan all files for the legacy encryption format. Use this to determine
351+
whether any files still need migration before disabling legacy format
352+
compatibility::
353+
354+
sudo -E -u www-data php occ encryption:scan:legacy-format
355+
Scanning all files for legacy encryption
356+
Scanning all files for layla
357+
All scanned files are properly encrypted. You can disable the legacy compatibility mode.
358+
359+
If files using the legacy format are found, their paths are listed. Run
360+
``encryption:drop-legacy-filekey`` to migrate them.

0 commit comments

Comments
 (0)