Samba fileserver on FreeBSD (Update FreeBSD 12)

published on in category FreeBSD NAS , Tags: freebsd samba selfhosted


  • 2019-01-30: Update guide for FreeBSD 12

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

It could be that the samba41 package is not available on your installation since you use a newer FreeBSD version like 12. In this case, just run pkg search samba and you will get a list of the available samba versions, like:

pkg search samba4
samba46-4.6.16_1               Free SMB/CIFS and AD/DC server and client for Unix
samba47-4.7.12                 Free SMB/CIFS and AD/DC server and client for Unix
samba48-4.8.7                  Free SMB/CIFS and AD/DC server and client for Unix

I’d go with the most recent one. 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.

I run this site without advertisement of any kind. All information is free and my only goal is to give back something to the amazing free software development community. If you find some value in this, please consider donating me a cup of coffee using PayPal. Thank you so much!