Permission Denied on Own Files

Nextcloud version (eg, 20.0.5): 24.0.4
Operating system and version (eg, Ubuntu 20.04): Fedora 34 Server
Apache or nginx version (eg, Apache 2.4.25): nginx 1.22
PHP version (eg, 7.4): 7.4.30

The issue you are facing:

I moved some folders from backup via terminal manually. Then set user permission to nginx user for all folders and files. I can see all files and folders on dashboard but can’t access any of them with an error of permission denied. I also tried below commands but didn’t help me.

find files/ -type f -print0 | xargs -0 sudo chmod 640
find files/ -type d -print0 | xargs -0 sudo chmod 750

Is this the first time you’ve seen this error? (Y/N): Y

The output of your Nextcloud log in Admin > Logging:

Error: fopen(/var/www/html/nextcloud/data/admin/files/folder/file.pdf): failed to open stream: Permission denied at /var/www/html/nextcloud/lib/private/Files/Storage/Local.php#377

[webdav] Fatal: Sabre\DAV\Exception\ServiceUnavailable: Could not open file at <<closure>>

0. /var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php line 85
1. /var/www/html/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php line 89
2. /var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php line 472
3. /var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php line 253
4. /var/www/html/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php line 321
5. /var/www/html/nextcloud/apps/dav/lib/Server.php line 358
6. /var/www/html/nextcloud/apps/dav/appinfo/v2/remote.php line 35
7. /var/www/html/nextcloud/remote.php line 166
   require_once("/var/www/html/n ... p")

GET /remote.php/dav/files/admin/folder/file.pdf

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

$CONFIG = array (
  'passwordsalt' => '',
  'secret' => '',
  'trusted_domains' =>
  array (
    0 => '',
  'datadirectory' => '/var/www/html/nextcloud/data',
  'dbtype' => 'mysql',
  'share_folder' => '/SHARE',
  'version' => '',
  'overwrite.cli.url' => '',
  'overwriteprotocol' => 'https',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'default_phone_region' => 'TR',
  'dbuser' => 'nextcloud',
  'dbpassword' => 'password',
  'installed' => true,
  'instanceid' => 'ocd9uqfbh7ov',
  'trashbin_retention_obligation' => '30,30',
  'enable_previews' => true,
  'preview_max_x' => '2048',
  'preview_max_y' => '2048',
  'preview_max_scale_factor' => 1,
  'enabledPreviewProviders' =>
  array (
    0 => 'OC\\Preview\\TXT',
    1 => 'OC\\Preview\\MarkDown',
    2 => 'OC\\Preview\\OpenDocument',
    3 => 'OC\\Preview\\PDF',
    4 => 'OC\\Preview\\MSOffice2003',
    5 => 'OC\\Preview\\MSOfficeDoc',
    6 => 'OC\\Preview\\PDF',
    7 => 'OC\\Preview\\Image',
    8 => 'OC\\Preview\\Photoshop',
    9 => 'OC\\Preview\\TIFF',
    10 => 'OC\\Preview\\SVG',
    11 => 'OC\\Preview\\Font',
    12 => 'OC\\Preview\\MP3',
    13 => 'OC\\Preview\\Movie',
    14 => 'OC\\Preview\\MKV',
    15 => 'OC\\Preview\\MP4',
    16 => 'OC\\Preview\\AVI',
    17 => 'OC\\Preview\\HEIC',
    18 => 'OC\\Preview\\HEIF',
    19 => 'OC\\Preview\\HEVC',
  'loglevel' => 2,
  'jpeg_quality' => '60',
  'filelocking.enabled' => true,
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'redis' =>
  array (
    'host' => 'localhost',
    'port' => 6379,
  'twofactor_enforced' => 'true',
  'twofactor_enforced_groups' =>
  array (
  'twofactor_enforced_excluded_groups' =>
  array (
  'maintenance' => false,
  'theme' => '',

you do chmod, ok. But chown ?? looks like a simple files ownership problem within linux.

1 Like

Who is the owner of the file?

I see the same. probably the the owner is not the nextcloud/web server user. On Debian/Ubuntu is the user www-data and the group www-data. On Fedorea maybe different.

Also interesting that at Fedora is the same sudo nonsense as in Ubuntu, which moreover you have applied incorrectly. sudo at the beginning of the lines or change to root and use the lines without sudo. Hopefully you didn’t break anything with chmod. Please do not repeat the both commands.

yes i already did chown -R nginx:nginx data/ folder

you are right but i ran the commands on root login and actually i fixed my issue but i don’t know why it worked

previously I used mv command to move folders in to the data directory. Now I used cp command to copy them to a different folder in data/ like data/folder_new then i ran chown -R nginx:nginx on it and finally i can access my folders so I can’t change permissions on folders that moved?

After mv or cp to data folders you must rescan the files. Otherwise Nextcloud does not know that they exist at all or are no longer at the old location.

sudo -u nginx php /path/to/nextcloud/occ files:scan --all


If you use Nextcloud mechanism to copy or move (Web, Apps, WebDAV) you do not need rescan.

Yes but i already scanned my files. When scan command visits the folder with permission error, it throws an error and cancels the operation.

Post some errors. Correct the rights tou your user. Is the Nextcloud user.

other than permission error i only get Interrupted by user error on scan command. I give the same permission and chmod, only thing i did differently was copying files from backup instead of moving to fix it