linux, networking, nextcloud, nextcloudpi

Share your files in your LAN with SAMBA

In order to complement last post about the NFS remote file system, in this post we will cover SAMBA. The main focus of this series is to document the possibilities of NextCloudPi, but it aims to be a general introduction to the technology.

Like NFS, SAMBA provides a remote file system that allows us to mount locally folders that are in reality in another computer.

SAMBA is a free and open source implementation of the SMB/CIFS (Server Message Block/Common Internet File System) by MicroSoft that was started in 1992.

SMB/CIFS is the protocol used in Windows networks to share files and printers, so SAMBA allows us to host files and printers that can be accessed from a Windows computer, as well as it allows a Linux computer to access files and printers shared in a Windows system.

Actually, it is so popular that Mac computers can also access SMB/CIFS remote filesystems, which makes SAMBA a good choice for “mixed” networks where we want to serve files to Linux, Windows, Mac computers… and even some Android applications are able to mount SMB/CIFS folders over the network.


This is a highlight of its features

  • The SAMBA server is implemented in userspace.
  • It is supported by multiple platforms
  • Its traffic is not encrypted, although it is in the roadmap of features
  • It provides authenticated access.
  • It can also share printers, combined with the CUPS printing server.

While the beauty of NFS its it’s simplicity, low resources requirements and the fact that it is implemented in the kernel, SAMBA is way more flexible, featureful and more appropriate for many setups except the most simple ones.

We have more control over the setup, as we can define different permissions for different users and the access is authenticated via username/password. Public shares can also be defined.

While installing the nfs-kernel-server only takes up 300 KB of our space, the smbd server takes around 40 MB.


Just install the appropriate package for your distribution, normally just samba.

In the case of NextCloudPi, just update to the latest version with

As usual, the generic installer can be used on any Debian based running server to install and configure through SSH, or on a Raspbian image through QEMU.

Default configuration (NextCloudPi only)

In the specific case of NextCloudPi, we usually want to share the data folder on the local network, so select samba in

DIR is the directory to share. The default will be /var/www/nextcloud/data/admin/files for user admin on a fresh installation. If you have moved the data folder to an external drive, then it might be more similar to the default /media/USBdrive/ncdata/admin/files. Note that this is the path for the files belonging to the user admin.

If you would like a different setup, read the next section.

Manual configuration

The main configuration file is located at /etc/samba/smb.conf. There are many resources online about the configuration of this file, but the comments inside it are pretty much self-explanatory.

A share is defined by a configuration block that can be as simple as this

If you want to be able to modify and delete files and folders from both Nextcloud and SAMBA mounts, you can add the following to the share

Users are controlled by smbpasswd, and smb.conf can be configured to synchronize their credentials with the Linux user credentials.

In order to add the user pi, type

Make sure that the shared folder can be accessed by allowed users through the regular system permissions system.


Once the share is in place, we can browse it from Windows, Mac, and such.

In order to browse shares in Linux, we make use of smbclient.

We can see the NextCloudPi share defined earlier. We can use smbclient to login to a terminal interface that allows us to browse, push and pull files.

However, this is not very comfortable to use. It is better to mount the remote share.

, or at boot from /etc/fstab

That is not ideal though, as the password will be shown in our history for the mount command, and  fstab is visible to all users.

It is better to save our credentials in a read-only file and use the option credentials.

The folder in the server at location /media/USBdrive/mysharedfolder will now be available in /mnt with those access permissions of user pi on that server.



Author: nachoparker

Humbly sharing things that I find useful [ github dockerhub ]

18 Comments on “Share your files in your LAN with SAMBA

  1. That’s great, but I couldn’t understand well how I’d do a setup like what I’ll describe. Could you please help me?
    – there’s only one user on the RPi, which is the default user Pi with changed password. I can add other users, if necessary;
    – NextCloudPi users are: admin (just admin stuff, I’d delete it if I could, but no big deal); me (username ‘alc’, with admin privileges); my partner (username ‘lif’, belongs to group ‘users’, no admin privileges);
    – user ‘lif’ should access her NextCloud data folder from her Macbook, and only her data folder, not ‘alc”s or ‘admin”s;
    – user ‘alc’ should only access his NC data folder, and only this folder, not the other users’;
    – users should be able to share files with each other through NC’s sharing feature, no need for sharing through samba, in principle.

    So, is it attainable? Could you please help me?

    On a side note, this NextCloudPi installation is just on the local network, no internet access – this is just for local wireless handling of files. Should I worry about SSL? Because I disabled ‘force HTTPS’.

    Thank you and props for the great work!

    1. I would create two samba users with smbpasswd, then two shares, one for each user ( valid users line ) at their Nextcloud data locations ( /media/USBdrive/ncdata/alc/files ).

      Finally, grant system permissions over the data folder, but always keep Nextcloud (user www-data) able to access. You can for example, change the group for the folder ( group alc ), and grant it read/write permissions.

      Regarding HTTPS… I think you can never be too paranoid, specially with private data. I would leave it on, because nowadays everything can access the internet. Say you have cheap chinese IoT toaster at home… it will be able to sniff your data and send it to the internet.

  2. hey nacho,

    do you know or/and would you be so kind an tell me on which protocol the installed samba bases? smb1, smb2 or smb3?

      1. thanks for your answer.

        >It would probably be a good idea to disable SMB1

        that was the reason for asking. how do i do that? and/or couldn’t you do that on default? just for security reasons?

  3. Hi nachoparker, do you have any updates on the encryption of samba.
    I would like to use samba to share movies but I’m concerned about the security as I have it connected to the internet.
    Any other ideas how I could stream movies from the pi to other devices in a secure way?

    1. well, samba is LAN only, so in principle, nobody would be able to access from outside because your router is on the way.

      if you want to stream movies, you can open movies from your browser with Nextcloud, or you could mount your video folder with SSHfs, or you could set up vlc as a server… first things that come to my head, but you can investigate, I might be missing something

  4. I can’t get this to work as all folders and files created under NextCloudPi are created with permission that doesn’t allow Samba to delete or amend, specifically the w(rite) bit is not set for the group www-data. Creating files or folders under Samba works great and NextCloud is able to deal with them without issue.

    Initally I ran;
    sudo chgrp -R www-data
    sudo chmod -R g+w

    sudo find -type d -exec chmod 2775 {} \;
    sudo find -type f -exec chmod ug+rw {} \;

    Which works great for all files and folders currently listed in NextCloud, but get NextCloud to create a new file or folder and it doesn’t create it with the w(rite) bit set for the group, seems the aforementioned commands would also need to be run everytime – seems very clumsy. What is the correct way to handle this?

  5. Hi there,
    I’m new to Nextcloudpi and Linux. I managed to install Nextcloudpi, now I only want to install a samba server to access the data from my Windows PC.

    I type in the following, and it works as far as I can say: “git clone

    Then I type “./”
    and I get the response “-bash: ./ No such file or directory”

    What am I doing wrong? Do I have to type in another IP address?
    It’s really bothering me that I can’t make it work. Please help

  6. Hi there,

    I was wondering if I can also add other nextcloud users to Samba by using your NextCloudPi Panel or do I have to do it manually?


  7. Thanks a lot for sharing this! The share was easily mounted in Windows or on my Smartphone!

    In Linux I had the problem that I could only write files as an administrator.
    The fix for that was to add “,uid=**linux-user**,gid=sambashare” to the end of the fstab line where I mount the share:

    //**server-IP**/ncp-ncp /mnt cifs credentials=/home/**linux-user**/.smbfile,uid=**linux-user**,gid=sambashare,rw,user 0 0

    Where the **linux-user** is a member of the gid sambashare.

  8. Hi All,
    I have the same problem with access to the user data over samba. Exactly the same stuff described by Alex Centim in first post.
    Nextcloud added automatically the samba users data in relation to the created accounts to the end of the smb.conf
    For example one looks like that;
    path = /media/USBdrive/ncdata/user1/files
    writeable = yes
    ; browseable = yes
    valid users = user1
    force user = www-data
    force group = www-data
    create mask = 0770
    directory mask = 0771
    force create mode = 0660
    force directory mode = 0770

    When I was turning on samba option in NextcloudPi panel it asked me to enter password. And it is assumed that the one password is related to all users. Which is strange for me.
    I can only connect one user from the 4 created. Using the one password for samba, not even the real user password.

    Another thing is that shared folders arent displayed in samba for that user. I have got group folders that are accessible for all users. But cannot see them in samba.

    Anyone can help to fix this issues.
    I add that I am new to linux and NC.


Leave a Reply

Your email address will not be published. Required fields are marked *