Server-side Encryption


目录

Overview

Nextcloud provides several encryption methods to protect your data. These work at different layers of the system and address different security needs. This guide focuses on Nextcloud's built-in Server-Side Encryption (SSE).

提示

Encryption and risk management is a complex and nuanced topic. Unless you are already an expert, it is recommended to consult a professional or perform a deep dive to ensure your approach targets your specific concerns. You may also find this Nextcloud Blog post helpful: Data encryption methods in Nextcloud. It provides a solid high-level overview of the different approaches commonly considered when using Nextcloud.

Definitions

Encryption Method Comparison

Method Encryption Location Who Can Decrypt? Protects Against
SSE (Master Key) Server Admins & users External storage providers
SSE (User Keys) Server Users & malicious admins External storage providers
SSE (User Keys w/ Recovery) Server Users & admins with recovery key External storage providers
E2EE Client Users only Admins, external storage providers
Disk/Block Encryption Server OS admin Physical tampering, theft

Key Points & Limitations

注意

SSE does not encrypt filenames or folder structures, only file contents.

提示

Don't confuse Nextcloud's SSE with S3 SSE-C (also supported).

Changed in version 9.0.0: Nextcloud (since v9.0.0) supports Authenticated Encryption for all newly encrypted files. See https://hackerone.com/reports/108082 for technical details.

提示

For maximum security, configure external storage with "Check for changes: Never". This causes Nextcloud to ignore new files not added via Nextcloud, preventing unauthorized additions by external storage admins. Do not use this if your storage is subject to legitimate external changes.

Before You Enable Encryption

  1. Read this guide fully and understand the risks.
  2. Back up your instance configuration and all encryption keys in a safe location before proceeding.
  3. Decide which key management mode suits your needs (see below).

Key Management Modes

Master Key (default):

User Keys:

How to choose:

To select user key mode:

Run:

occ encryption:disable-master-key

before enabling encryption.

Enabling Encryption (Step-by-Step)

  1. Go to the Server-side encryption section of your Admin page.
  2. Check Enable server-side encryption.
  3. You’ll see a message: "No encryption module loaded." Go to your Apps page and enable the Nextcloud Default Encryption Module.
  4. Return to your Admin page. The module will appear and be auto-selected.
  5. Log out and log back in to initialize your encryption keys.
  6. Optional: Un-check the box for encrypting home storage if you wish to keep local files unencrypted.

Backups

Encryption keys are stored in:

Encrypting External Mountpoints and Team Folders

occ config:app:set groupfolders enable_encryption --value=true

提示

Only new or updated files in team folders will be encrypted.

Managing Encryption via occ Commands

Here is a reference table for common occ commands:

Command Description
occ encryption:status Show encryption status and module
occ encryption:enable Enable server-side encryption
occ encryption:list-modules List available encryption modules
occ encryption:set-default-module [Module ID] Select default encryption module
occ encryption:encrypt-all Encrypt all files for all users
occ encryption:decrypt-all [user] Decrypt all files (or for one user)
occ encryption:show-key-storage-root Show key storage location
occ encryption:change-key-storage-root [dir] Move key storage directory
occ encryption:enable-master-key Enable master key mode
occ encryption:disable-master-key Disable master key mode
occ encryption:fix-encrypted-version Fix bad signature errors
occ encryption:fix-key-location [user] Fix key not found errors

提示

See the Encryption commands section of the occ reference guide for further encryption command examples and details.

Example: Move keys to a new directory (Ubuntu Linux):

cd /your/nextcloud/data
mkdir keys
chown -R root:www-data keys
chmod -R 0770 keys
occ encryption:change-key-storage-root keys

Encrypting All Files

By default, only new and changed files are encrypted when you enable SSE. To encrypt all files for all users run:

occ encryption:encrypt-all

Decrypting Files / Disabling Encryption

occ encryption:decrypt-all

You can decrypt for individual users:

occ encryption:decrypt-all <user-id>

Data Not Encrypted

Only file contents are encrypted. The following are not encrypted:

Not Encrypted
Filenames and folder structures
Existing trash bin files
Existing historical file versions
Image thumbnails
Image previews
Full text search index
Application data that isn't file-based (e.g., Deck, Tables)

User Keys: Sharing & Recovery

Sharing encrypted files:

Enabling file recovery keys:

Recovery keys are only available in per-user key mode (not the default master key mode).

注意

The recovery process can be slow and resource-intensive, especially for instances with large amounts of encrypted data. Test recovery procedures before relying on them in production.

LDAP and External User Backends

Troubleshooting

Why don't I see the recovery key option in the Encryption settings?

Recovery keys are only available in per-user key mode. Since Nextcloud 13, the default encryption mode uses master keys (system-wide encryption). Master key mode does not expose recovery key options in the Admin settings because recovery keys are not needed—admins can reset user passwords and files remain accessible.

If you are using master key mode (the default and recommended mode), you do not need recovery keys. Recovery keys are only relevant for per-user key setups, which are maintained for compatibility with older deployments.

See Key Management Modes for guidance on the differences between master key and per-user key modes, and GitHub Issue #8283 for technical context on this design decision.

Invalid private key for encryption app

See GitHub Issue #8546 and workaround.

Bad signature error

In some rare cases, encrypted files cannot be downloaded and return a "500 Internal Server Error." If the Nextcloud log contains an error about "Bad Signature," run the following command to repair affected files:

occ encryption:fix-encrypted-version userId --path=/path/to/broken/file.txt

Replace "userId" and the path accordingly. The command will perform a test decryption for all files and automatically repair those with a signature error.

Encryption key cannot be found

If the logs contain an error stating that the encryption key cannot be found, you can manually search the data directory for a folder that has the same name as the file name. For example, if a file "example.md" cannot be decrypted, run:

find path/to/datadir -name example.md -type d

Then check the results located in the files_encryption folder. If the key folder is in the wrong location, move it to the correct folder and try again.

The data/files_encryption folder contains encryption keys for group folders and system-wide external storages, while data/$userid/files_encryption contains the keys for specific user storage files.

提示

This can happen if encryption was disabled at some point but the occ command for decrypt-all was not run. If someone then moved the files to another location, the keys did not get moved.

Encryption key cannot be found with external storage or group folders

To resolve this issue, run the following command:

sudo -E -u www-data php occ encryption:fix-key-location <user-id>

This will attempt to recover keys that were not moved properly.

If this doesn't resolve the problem, refer to the section Encryption key cannot be found for a manual procedure.

提示

There were two known issues where:

Further Reading


版本号 #3
由 cocobook-sync 创建于 2026-10-28 16:28:03 UTC
由 cocobook-sync 更新于 2026-10-29 01:09:19 UTC