Skip to content

Nextcloud: External directory for one user

Nextcloud supports mounting external folders as storage for specific users. This solves data isolation, quota application, or providing access to a shared directory without cluttering the main storage.

Why need external directory

In scenarios where a single user or service requires dedicated space, creating an external directory separately from the main Nextcloud storage is more convenient. This allows: — Applying separate access rights to the folder. — Setting quotas at the filesystem level. — Ensuring backup or synchronization of a specific user without affecting others. — Allowing the user to manage their files via the web interface or WebDAV without access to other parts of the instance.

Prepare directory and access rights

Before adding the storage to Nextcloud, prepare a folder on the host. Example for user alice:

# Create directory
sudo mkdir -p /data/nextcloud/alice

# Set owner (ensure www-data can read/write)
sudo chown -R www-data:www-data /data/nextcloud/alice

# Set basic permissions (read/write/execute)
sudo chmod 2770 /data/nextcloud/alice

If SELinux is enabled (CentOS/RHEL), the context may be required:

sudo restorecon -Rv /data/nextcloud/alice
Tip

Use ACLs for fine-grained tuning if needed, so that Nextcloud and other processes have different access masks.

Configure external storage in Nextcloud

Enable the External Storage app (usually included in the base package). A storage can be added via the web interface or occ. For an external folder, select type Directory.

Key parameters when adding via occ (syntax may vary depending on version, but the essence is universal):

ParameterDescription
userIdNextcloud user ID the storage belongs to
rootFolderIdID of the root folder inside Nextcloud (usually -1 means the user’s root)
volumeIdVolume identifier (any unique string)
isReadOnlyRead-only flag (true/false)
loginNameUsername for authentication, if required

Example adding via occ (path specified absolute, accessible to the web server):

sudo -u www-data php /var/www/nextcloud/occ external-storage:add \
  --type directory \
  --params '{"userId":"1","rootFolderId":"-1","volumeId":"alice-data","isReadOnly":"false","path":"/data/nextcloud/alice"}'

After adding, verify the folder appears in user alice’s list.

Warning

Do not specify paths accessible only to root processes without explicitly switching the web server user. Permission denied at the mount stage is a typical trap.

Check functionality and typical errors

After configuration, log in as user alice and verify the folder mounts and files create in /data/nextcloud/alice.

Common causes of failure:

  1. Mismatched owner — the folder belongs to a different user or group, and the web server lacks write rights. Fix: chown www-data:www-data /path and verify chmod.
  2. SELinux / AppArmor — security context blocks web server access to the folder. Fix: restorecon -Rv /path or policy configuration.
  3. Paths with spaces or special characters — always use quotes in occ parameters and avoid paths with spaces without escaping.
  4. Missing External Storage app — ensure the app is enabled (occ app:enable externalstorage or via admin UI).
  5. Incorrect userId — the occ command may succeed, but the folder won’t appear in the UI if the user ID doesn’t exist or is wrong.

For diagnostics, list external storages:

sudo -u www-data php /var/www/nextcloud/occ external-storage:list

If the path is correct but files don’t appear, check the Nextcloud data/ structure and .htaccess settings or trusted_proxies if access comes through a reverse proxy.

In most cases, the issue is resolved by correcting the folder owner and re-running the occ command with output verification.