Samba fileserver on FreeBSD (Update FreeBSD 12)

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

Changelog

  • 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:

kern.maxfiles=25600
kern.maxfilesperproc=16384
net.inet.tcp.sendspace=65536
net.inet.tcp.recvspace=65536

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

aio_load="YES"

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

kldload aio

Installation

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:

[global]
    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.