# Occ files:scan -\> samba Permission denied

**URL:** <https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051>\
**Category:** ℹ️ Support\
**Tags:** external\_storage, smb, nc18-nextcloud-hub\
**Created:** [May 10, 2020, 1:33pm UTC](https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051 "2020-05-10T13:33:50Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael2222](https://help.nextcloud.com/letter_avatar/michael2222/32/5_5575768a8748004e209b776fc1b2916d.png) [@Michael2222](https://help.nextcloud.com/u/Michael2222)\
**Post date:** [May 10, 2020, 1:33pm UTC](https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051/1 "2020-05-10T13:33:50Z")

</div>

Hello,

I have in use a nc 18.04 (intel i5) and the files of a external discstation from synology connected with samba.

If I call "sudo -u www-data php occ files:scan " the error message

`mkdir failed on directory /var/run/samba/msg.lock: Permission denied`

occured.

The /var/run/samba/ folder is root:root:

```
drwxr-xr-x 3 root root 60 Apr 30 06:08 .
drwxr-xr-x 34 root root 1160 Mai 10 14:42 ..
drwxr-xr-x 2 root root 60 Apr 30 06:08 upgrades
michael@nextcloud:/var/run/samba$

```

Must this www-data:www-data to work fine?

Regards  
Michael

---

<div class="post-metadata">

**Author:** ![KarlF12](https://help.nextcloud.com/user_avatar/help.nextcloud.com/karlf12/32/46873_2.png) [@KarlF12](https://help.nextcloud.com/u/KarlF12)\
**Post date:** [May 10, 2020, 1:53pm UTC](https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051/2 "2020-05-10T13:53:18Z")

</div>

Do you have samba mounted by the OS or by Nextcloud?

---

<div class="post-metadata">

**Author:** ![Michael2222](https://help.nextcloud.com/letter_avatar/michael2222/32/5_5575768a8748004e209b776fc1b2916d.png) [@Michael2222](https://help.nextcloud.com/u/Michael2222)\
**Post date:** [May 10, 2020, 2:22pm UTC](https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051/3 "2020-05-10T14:22:25Z")

</div>

By Operating System

---

<div class="post-metadata">

**Author:** ![KarlF12](https://help.nextcloud.com/user_avatar/help.nextcloud.com/karlf12/32/46873_2.png) [@KarlF12](https://help.nextcloud.com/u/KarlF12)\
**Post date:** [May 10, 2020, 4:16pm UTC](https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051/4 "2020-05-10T16:16:39Z")

</div>

For any file access not carried out inside Nextcloud itself, it will be done in the context of the user www-data. Make sure the www-data user can access the mounted share.

---

<div class="post-metadata">

**Author:** ![Michael2222](https://help.nextcloud.com/letter_avatar/michael2222/32/5_5575768a8748004e209b776fc1b2916d.png) [@Michael2222](https://help.nextcloud.com/u/Michael2222)\
**Post date:** [May 10, 2020, 5:12pm UTC](https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051/5 "2020-05-10T17:12:48Z")

</div>

> [@KarlF12](#):
>
> Make sure the www-data user can access the mounted share.

I have mounted my discstation folder my this:  
`sudo mount 192.168.178.188:/volume3/FC_Daten/daten /media/fc_daten`

and this folder have www-data rights:  
`drwxrwx--- 1 www-data www-data 4282 Mai 10 19:05 fc_daten`

But the error message is:  
`mkdir failed on directory /var/run/samba/msg.lock: Permission denied`

and this folder have root:root

```auto
drwxr-xr-x 3 root root 60 Apr 30 06:08 .
drwxr-xr-x 34 root root 1160 Mai 10 14:42 ..
drwxr-xr-x 2 root root 60 Apr 30 06:08 upgrades
michael@nextcloud:/var/run/samba$

```

So my question is: Should I change the owner to www-data:www-data for this folder also?

---

<div class="post-metadata">

**Author:** ![KarlF12](https://help.nextcloud.com/user_avatar/help.nextcloud.com/karlf12/32/46873_2.png) [@KarlF12](https://help.nextcloud.com/u/KarlF12)\
**Post date:** [May 10, 2020, 5:38pm UTC](https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051/6 "2020-05-10T17:38:03Z")

</div>

I’m a little unclear on exactly what you’re trying to do. What is Nextcloud’s relation to /media/fc\_daten ?

---

<div class="post-metadata">

**Author:** ![Michael2222](https://help.nextcloud.com/letter_avatar/michael2222/32/5_5575768a8748004e209b776fc1b2916d.png) [@Michael2222](https://help.nextcloud.com/u/Michael2222)\
**Post date:** [May 10, 2020, 7:34pm UTC](https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051/7 "2020-05-10T19:34:10Z")

</div>

/media/fc\_daten is the document root from my nextcloud

---

<div class="post-metadata">

**Author:** ![devnull](https://help.nextcloud.com/user_avatar/help.nextcloud.com/devnull/32/27793_2.png) [@devnull](https://help.nextcloud.com/u/devnull)\
**Post date:** [May 11, 2020, 6:18am UTC](https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051/8 "2020-05-11T06:18:11Z")

</div>

> [@Michael2222](#):
>
> mkdir failed on directory /var/run/samba/msg.lock: Permission denied

mkdir and /var/run/samba/msg.lock makes no sense on “occ files:scan”.  
Sorry. No further Idea.

Please cut-and-paste command and error in one code-block. Thanks.

---

<div class="post-metadata">

**Author:** ![mfreudenberg](https://help.nextcloud.com/letter_avatar/mfreudenberg/32/5_5575768a8748004e209b776fc1b2916d.png) [@mfreudenberg](https://help.nextcloud.com/u/mfreudenberg)\
**Post date:** [June 12, 2020, 8:40am UTC](https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051/9 "2020-06-12T08:40:52Z")

</div>

I have the same issue on my setup. Here is the output from my occ files:scan --all:

```
mkdir failed on directory /var/run/samba/msg.lock: Permission denied
Protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE

```

My nextcloud 18.0.4 runs in a proxmox lxc with the data dir mounted to /mnt/data. the fstab is as follows

```
//192.168.178.47/nextcloud/data /mnt/data cifs rw,vers=3.0,credentials=/root/.smbcred,uid=www-data,gid=www-data,file_mode=0770,dir_mode=0770 0 0
```

---

<div class="post-metadata">

**Author:** ![castillo92](https://help.nextcloud.com/user_avatar/help.nextcloud.com/castillo92/32/26776_2.png) [@castillo92](https://help.nextcloud.com/u/castillo92)\
**Post date:** [December 28, 2020, 2:52pm UTC](https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051/10 "2020-12-28T14:52:55Z")

</div>

I have the same issue:

This is the commands I used:

```
sudo -u www-data php /var/www/nextcloud/occ files:scan --all
sudo -u www-data php /var/www/nextcloud/occ files:scan-app-data

```

And this is the output:

```
Starting scan for user 1 out of 1 (castillo92)
mkdir failed on directory /var/run/samba/msg.lock: Permission denied
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 1628 | 17924 | 00:00:09 |
+---------+-------+--------------+
Scanning AppData for files

+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 6774 | 2606 | 00:00:21 |
+---------+-------+--------------+
```

---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 12, 2024, 6:51am UTC](https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051/11 "2024-12-12T06:51:19Z")

</div>



---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 12, 2024, 6:51am UTC](https://help.nextcloud.com/t/occ-files-scan-samba-permission-denied/81051/12 "2024-12-12T06:51:20Z")

</div>


