Access/Share Nextcloud Data Folder Through Samba Server


I’ve setup a nexlcoud server under ubuntu 20.04 on an old computer. My main use is to access my files from everywhere and sync some folder (eg on my phone). I don’t want to sync all automaticaly all my folders but i wan’t to sync them manually with a chek of modifications on each sides with syncback.
I wanted to access my nextcloud folder (located in my home) with samba server i installed but it is impossible since the owner is www-data. I can access the folder only with nautilus.
I have tried to mount my nextcloud as an external drive but it is very slow even in LAN especially with littles files. Is there a way change permissions in order to access my nexcloud data folders from windows using samba server ? Can I put add data a standard samba user into the group www-data ?I am afraid of damaging the nextcloud configuration

If I’ve got your idea right, you want to share your Nextcloud data directory using a Samba server. Or, in other words, use “Samba on the top of Nextcloud” option.
Don’t you think “Samba side by side with Nextcloud” option is more suitable for you?


I’m not very fluent in English so it’s a bit difficult to explain in english
I have set my nextcloud data folder is under my home directory. I need to enter my password to browse in wit nautilus because the owner is www-data

I have already samba installed and can access to my home folder but not the nextcloud folder.
I wanted to use syncback to backup some folder time to time in nextcloud directory with a check of differences. After i can run /occ files:scan --all to update nextcloud database . I don’t want to synck these folder with the nexcloud client.
I don’t kno why but when i access no nextcloud through netdav (eg with netdrive) it i very slow, slower than with the web interface.

Well there is not really an elegant way to achieve what you want…

  1. The file copy operation must be performed by a user who has write permissions on the Nextcloud Data folder
  2. After you made any changes directly in the Nextcloud Data Folder, you have to run occ-files scan.
  3. For security reasons, I would not recommend to share your Nextcloud Data Folder via SAMBA and / or mount it permanently on your PC.

So if you you absolutely have to copy the files directly to the Nextcloud Data Folder, here’s what I would do:

Create a user on the server and add that user to the www-data group:

adduser <username>
usermod -a -G www-data <username>

Use a tool like WinSCP or Filezilla to connect to your server with the previously created user and upload the files to the Nextcloud Data Folder…

After you uploaded the files, run the following commands on the server:

sudo -u www-data php /path/to/nextcloud/occ files:scan --all
chown -R www-data:www-data /var/nextcloud-data
find /path/to/nextcloud-data/ -type d -exec chmod 750 {} \;
find /path/to/nextcloud-data/ -type f -exec chmod 640 {} \;

Nextcloud uses a SQL database for some functions related to file operations. Using Samba means your Nextcloud may be out of sync and may break things. (even with the filescan).

I would advise against this. Either use Samba OR Nextcloud.

@jhjacobs81 I agree, that it doesn’t make sense to share the Nextcloud data folder via SMB, for various reasons, and I also advise against it. However you absolutely can copy files directly to the Data Folder, if you get the permissions right and perform an occ files-scan afterwards.

@corias To be clear, the method I posted should only be used for occasional large file uploads, not to actually “work” with the files in the Data Folder on a daily basis. Use the Nextcloud Desktop Client or WebDAV for daily usage. If that doesn’t fit your needs for a specifc usecase, @jhjacobs81 is right, and you probably should use SAMBA instead of Nextcloud for these files.

1 Like

I agree that you agree that we agree :slight_smile: I too, have in the past copied files through SMB, but it always gave me more troubles then its worth.

1 Like

Depending on the use case you could also mount a folder outside of your Nextcloud Data Folder and connect it to Nextcloud via external storage app. That way you don’t need to execute occ files:scan, but you still need to get permissions and file ownerships right, otherwise you will likely run into issues further down the road…

Or you could use a separate NAS, create a SAMBA share on that, and then add it to Nextcloud via External Storage App and also mount it on your PC as a network drive. But honestly, I would avoid that too, if not absolutely necessary.

In theory you could also share a folder from your PC via SAMBA and then add it to your Nextcloud via External Storage App directly… Seriously! Don’t do that! :wink:

The best way would be to address the performance issues of WebDAV, and then use that exclusively.

Thanks for all the replies. I will avoid access my NC datafolder through samba. I just don’t want to sync automatically all my datas with th NC client.
I find the possibility of loosing data in my source too risky when many files are sync. That’s why I use syncback ton compare changes on both sides (source/destination).
Mounting nexcloud as a network drive using WebDAV will be enough but it took me more than 1 hour to transfer 150MB…transferring big files are ok but many small file is too slow and is much more speed through samba

You can use WebDAV you posted below. Also you can use Virtual files

This is exactly where you have a thinking error. Nextcloud is not a backup and does not want to be a backup. You should better think about a backup concept than restricting the functions of Nextcloud.

Nextcloud Backup and Nextcloud Restore.

Why do you not use normal Nextcloud functions e.g. Nextcloud clients? And maybe you use Nextcloud for the wrong thing. Hopefully the 150 MB with small files are not client files you want to backup to a backup server. Nextcloud is not a backup solution. But Samba is also no backup software. :wink:

Finally i moved the files under my nc data folder and run “sudo -u www-data php /path/to/nextcloud/occ files:scan --all”…
I get an error msg and the PC freeze…
Know when I try to open a photo through nc web I get a blank picture with “Error loading…jpg”
It seems the database is corrupt ?

Is there a way to fix it ?

I’m a little surprised that the sudo command works at all when run as victor.

Please change first victor to root:
sudo -s
And then:
sudo -u www-data php /var/www/nextcloud/occ files:scan --all

Is there a difference?

No, it does not change

Yea this is easy and no problem if you layer it all correctly.

Assume, samba server, and nextcloud are same server, where the data resides. Just use default nextcloud data folder during nextcloud installation.

Then create your user data structure on the linux file system, just normal linux folders:


Login to nextcloud as an administrator, create user ‘Bob’

Install ‘external storage’ app.

Configure a new external storage for Bob in nextcloud settings:
Choose “local” as the backend
Set folder to /
Set configuration to: /opt/userfolders/Bob
Give access to: choose ‘Bob’ from the list

Now you can configure samba to create a smb share ‘bobdata’ or whatever to share /opt/userfolders/Bob

So the same physical linux folder is now shared via smb, and accessible via nextcloud user bob.

No occ-scan stuff needed since we’re using the external storage mechanism instead of the actual ‘data’ directory that has those restrictions.

Just watch out for file versioning. Versioned files go into the nextcloud data dir, not the user dir.

And permissions will need to be set appropriately for bob/samba/www-data on the physical folder for all the users and services to be able to read write on /opt/userfolders/Bob