TechBuzzPro

Detect Unauthorized File & App Changes in Nextcloud

· 5 min read · Apps & Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Nextcloud gives you built-in tools to detect unauthorized file changes and app modifications, but you need to enable and check them manually. The core methods are the audit log (for file and app activity), the integrity checker (for app code tampering), and file change notifications. This guide walks you through each, from the admin interface to command-line checks.

What You'll Need

  • Administrator access to your Nextcloud instance (web UI or command line).
  • SSH or terminal access to the server running Nextcloud (for command-line commands).
  • The Audit log app enabled (it's part of the default Nextcloud installation, but must be enabled in the Apps section).
  • Basic familiarity with your server's file system and command line.

Step-by-Step

1. Enable the Audit Log

  1. Log in to Nextcloud as an administrator.
  2. Go to Apps (top-right menu) and search for “Audit log”.
  3. If it’s not already enabled, click Enable. (Labels may vary slightly by version.)
  4. Once enabled, the audit log records file uploads, downloads, deletions, and app installations/uninstallations.

2. Review the Audit Log

  1. Go to Settings (top-right menu) and select Administration settings.
  2. Look for the Audit log section (sometimes under “Security” or “Logging”).
  3. Review entries for file operations (e.g., “created”, “updated”, “deleted”) and app actions (e.g., “app installed”, “app updated”).
  4. Filter by user or time range to spot suspicious activity. Look for actions you didn't perform or that occur at odd hours.

3. Run the Integrity Check

  1. Open a terminal and SSH into your Nextcloud server.
  2. Navigate to the Nextcloud installation directory (e.g., cd /var/www/nextcloud).
  3. Run the integrity check command: sudo -u www-data php occ integrity:check-core (replace www-data with your web server user).
  4. If any files fail the check, the output will list them. This indicates the core code has been modified, which could be a sign of tampering.
  5. To check installed apps, run: sudo -u www-data php occ integrity:check-app <appname> (replace <appname> with the app's folder name, e.g., calendar).

4. Set Up File Change Notifications

  1. As an admin, go to Settings > Administration settings > External storages (if you use external storage) or Files.
  2. Enable the File change notifications feature (if available in your version). This sends an email or notification to admins when files are changed by users.
  3. Configure the notification settings (e.g., which users to notify, what events trigger a notification).

5. Monitor App Updates Manually

  1. In the Apps section, review the list of installed apps periodically.
  2. Check the “Last updated” column (if visible) to see if any app was updated without your knowledge.
  3. If you suspect an unauthorized app change, go to Settings > Administration settings > Apps and look for any apps you didn't install.

6. Use Command-Line for Detailed Logs

  1. SSH into your server and navigate to the Nextcloud directory.
  2. Run sudo -u www-data php occ log:file to see the application log (this may be large).
  3. Look for entries related to file activity or app changes, especially those with “error” or “warning” levels.
  4. You can also check the web server access logs (e.g., /var/log/apache2/access.log) for unusual requests to the Nextcloud endpoints.

Common Mistakes

  • Not enabling the audit log – it's off by default in many installations, so you won't have any record of changes.
  • Running the integrity check as the wrong user – use the same user that runs the web server (often www-data), otherwise you'll get permission errors.
  • Ignoring integrity check failures – even a single failed file can mean tampering; don't dismiss it as a false positive without checking the file.
  • Only checking core, not apps – apps can be modified too, so run the integrity check on each installed app.

Tips

  • Schedule a weekly cron job to run the integrity check and email the output to you.
  • Enable two-factor authentication for admin accounts to reduce the risk of unauthorized access.
  • Regularly back up your Nextcloud data and configuration so you can restore if tampering is detected.
  • Use the occ command maintenance:mode to put the server in maintenance mode before making manual changes, so you can track your own actions.
  • Consider using a file integrity monitoring tool (like Tripwire) on the server itself for an extra layer of detection.

Troubleshooting

Integrity check returns errors for core files

If you see “File … has a different hash”, it could be due to a failed update or manual modification. Try re-running the update: sudo -u www-data php occ upgrade. If that doesn't fix it, you may need to re-download the Nextcloud code from the official source and replace the affected files (back up first).

Audit log shows no entries

First, ensure the Audit log app is enabled. If it is, check that the logging level in config.php is set to at least “warning” (the default). Also, verify that the log file is writable by the web server user.

File change notifications not working

Make sure the notification app is enabled and that the admin email address is correct in Settings > Administration settings > General. Also, check that cron jobs are running – notifications often depend on cron.

Can't find the audit log section

In some Nextcloud versions, the audit log is under Settings > Administration settings > Security or Logging. If you don't see it, try searching “audit” in the settings search bar. If it's still missing, the app might not be installed – go to Apps and install it.

Frequently Asked Questions

Can I detect who changed a specific file?

Yes, the audit log records the user who performed file operations (upload, delete, etc.). You can filter the log by file name or user to see who did what.

Does the integrity check cover all apps?

No, you must run it per app. Use occ integrity:check-app <appname> for each installed app. Some third-party apps may not be signed, so they will always fail – that's normal for unofficial apps.

What if I use external storage like S3?

File changes on external storage are still logged in the audit log, but the integrity check only applies to the Nextcloud codebase, not external storage content. For external storage, enable object storage versioning or use the provider's own monitoring.

How often should I run the integrity check?

At least weekly, or after any update or manual change. Automating it with a cron job is recommended.

Can I get alerts for unauthorized changes?

Yes, you can configure the audit log to send email notifications (if your Nextcloud supports it), or use a custom script that parses the log and sends alerts. The built-in file change notifications also alert admins.

Is there a way to prevent changes altogether?

You can restrict admin privileges to trusted users, use strong passwords and 2FA, and keep your Nextcloud updated. However, a determined attacker with server access can bypass these – so server-level security is also crucial.