Folder permissions: "Permission denied (os error 13)"

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • 31.0.0
  • Operating system and version (e.g., Ubuntu 24.04):
    • `TrueNAS ElectricEel-24.10.2``
  • Web server and version (e.g, Apache 2.4.25):
    • dunno
  • Reverse proxy and version _(e.g. nginx 1.27.2)
    • ???
  • PHP version (e.g, 8.3):
    • 8.3.17
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • TrueNAS app
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • No(?)

Summary of the issue you are facing:

Attempting to use a deduping app (Czkawka) to delete dplicate files in NextCloud’s /var/www/html/data/<username>/files folder fails with “Permission denied (os error 13)” error.

Steps to replicate it:

  1. run Czkawka on /storage (mapped to NextCloud’s /var/www/html/data/<username>/files–see comment below)
  2. select duplicate files to be deleted
  3. click the “Delete” button
  4. witness the error message: “Failed to delete file /storage/path/to/file/filename reason Permission denied (os error 13)”

Comments:

The NextCloud /var/www/html/data/<username>/files folder is actually mapped to TrueNAS’ /mnt/NextCloud/data/<username>/files folder, which, in turn, maps to Czkawka’s /storage folder. Thus, in Czkawka, search happens in /storage. As I was saying, search works fine, but deletion does not.

I thus examined who the owner of the /var/www/html/data/<username>/files folder is:

root@nas1[/mnt/NextCloud/data/dad]# ls -latr
total 36
drwxr-xr-x  5 apps     apps     11 Mar  7 16:53 files
drwxrwx---  4 www-data www-data  8 Mar  7 16:59 ..
drwxr-xr-x  2 www-data www-data  2 Mar  7 17:06 cache
drwxr-xr-x  7 www-data www-data  7 Mar  7 19:03 .
drwxr-xr-x  5 www-data www-data  5 Mar  7 19:03 files_trashbin
drwxr-xr-x  3 www-data www-data  4 Mar  7 19:18 files_versions
drwxr-xr-x 32 www-data www-data 32 Mar  8 18:13 uploads

The question is, then, should I run Czkawka as this apps user? Problem is, Czkawka cannot run as apps. What to do?

Refer to TrueNAS forum topic for more details.

You have to run it under the same user as the Nextcloud user. It looks like this is the user www-data in your case.

But if you delete something, it will be missing in the Nextcloud database and you will probably have to do a rescan with the occ command.

Thanks, I will attempt to run Czkawka as this user see if it even works, and report back.

Edit: just as I suspected, Czkawka does not run as www-data, just as it does not run as apps either: it crashes or it just simply stops!

Apologies! I take back what I said about the apps and www-data users: they are actually TrueNAS built-in users, so they do exist!

Regardless, it looks like Czkawka cannot be run as any of these users. Heck, I even attempted to run Czkawka as root, and it still does not run!