Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions admin_manual/installation/harden_server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,47 @@ Also set it for CLI work (``occ``, cron):
.. seealso:: :doc:`../configuration_server/config_sample_php_parameters` for full details on
``NEXTCLOUD_CONFIG_DIR`` and other configuration loading behaviour.

Set strong file permissions
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Strong file system permissions reduce the attack surface if an attacker gains
access to the web server process. The recommended baseline restricts world
access to the Nextcloud installation directory:

.. code-block:: bash

# Set ownership to the web server user and group
sudo chown -R www-data:www-data /var/www/nextcloud/

# Files: owner read/write, group read-only, no world access
sudo find /var/www/nextcloud/ -type f -print0 | sudo xargs -0 chmod 0640

# Directories: owner full, group read+execute, no world access
sudo find /var/www/nextcloud/ -type d -print0 | sudo xargs -0 chmod 0750

The **data directory** must remain writable by the web server user:

.. code-block:: bash

sudo chown -R www-data:www-data /path/to/nextcloud-data/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a chmod as well, no?


If you install or update apps via the Nextcloud **app store**, the ``apps/``
directory also needs to be writable by the web server:

.. code-block:: bash

sudo chown -R www-data:www-data /var/www/nextcloud/apps/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already covered by the chown on /var/www/nextcloud/.


.. note::

The built-in **web updater** requires write access to the entire Nextcloud
installation directory. If you apply stricter permissions that prevent
web server writes, the web updater will fail. Disable it first by adding the following to
``config/config.php``, then use the command-line updater or package
manager instead::
Comment on lines +144 to +148
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how to apply these stricter permissions? If the owner of the files is www-data and owner has read/write the webserver has write access. So is it with a chown to root? Joas seemed to say this is preventing all upgrades 🤔


'upgrade.disable-web' => true,

Disable preview image generation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
Loading