Samba fileserver on FreeBSD

published on on Selfhosted, Samba, FreeBSD

While building my new NAS, I came across the question how to install a fileserver based on Samba on FreeBSD. Here's how...

Kernel options tuning

First, let's tune some kernel settings to optimize handling of many files. Edit /etc/sysctl.conf and add the following lines:


Also, we should enable asynchronous I/O. This can be accomplished by adding the following line to the file /boot/loader.conf:


To get it working without restarting, additionally execute the following command:

kldload aio


Then we can install Samba. I'm using prebuilt binaries, so we're using pkg here:

pkg install samba41

Sadly, the package does not provide a default configuration file, so running testparm, which is Samba's config test tool results in an error stating that the configuration file does not exist.

So we need to create a file called /usr/local/etc/smb4.conf. Here's mine, just change it to match your needs:

    workgroup = MYGROUP
    realm = mygroup.local
    netbios name = NAS

[davd data]
    path = /home/davd
    public = no
    writable = yes
    printable = no
    guest ok = no
    valid users = davd

Then just enable Samba and start it:

sysrc samba_server_enable=YES
service samba_server start

User creation

Now that the server is running, you can't still access your files because you got no credentials to log in with. By default Samba relies on system users, so after you created your system user using adduser, enable it for Samba:

pdbedit -a -u davd

You are prompted to enter a password which will be used to authenticate against Samba.