Samba Filesharing Server on OpenBSD for macOS Client

May 22, 2019

Introduction

I do most of my work on one of two MacBooks—a 2014 Air or 2018 Pro—and occasionally on an older model Lenovo ThinkPad running OpenBSD 6.5. Staying synced between the two Macs is trivial as they’re both in the cloud but apart from using my own Nextcloud server on an OpenBSD VPS for storing some personal data, I wanted a seamless option for filesharing between the ThinkPad and MacBooks when at home on the local network. This was a relatively pain-free task that took all of five minutes.

Package Installation

First, install Samba. OpenBSD has made this as easy as 10,000 other packages with pkg:

# pkg_add samba

Required dependencies will install automatically. Once finished, you can read the post-install documentation provided but configuration is really simple so you can skip this if you trust my instructions (hint: always read the documentation):

$ cat /usr/local/share/doc/pkg-readmes/samba

It’s a relatively short file but it points you to a comprehensive configuration example file, which you should read to get an idea of the available options:

$ cat /usr/local/share/examples/samba/smb.conf.default

Samba Setup

After a thorough read of the provided documentation, open /etc/samba/smb.conf and set your desired options. Mine follow:

[global]
workgroup = HOMELAND
server string = %h server
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=8192 SO_SNDBUF=8192
dns proxy = no
log file = /var/log/samba/%m.log
max log size = 1024
syslog = 3
server role = standalone
hosts allow = 10.0.0.0/255.255.255.0 127.0.0.1
map to guest = Bad User
invalid users = root

[t420]
path = /home/mark
writable = yes
browseable = yes
valid users = mark

But you can make do with a rather minimal smb.conf with the following that will even allow guest users access to a limited guest account:

[global]
workgroup = WORKGROUP
server string = Samba File Server
dns proxy = no
log file = /var/log/samba/%m.log
max log size = 1024
server role = standalone
map to guest = Bad User

[fileshare]
path = /home/username
guest ok = yes
writable = yes
browseable = yes
public = yes

If the path maps to a non-existent directory (i.e., the user doesn’t exist and you don’t want to create a new user), make it now:

# mkdir /home/username
# chown nobody:nobody /home/username

You’re now ready to start the file server.

Start Samba Service

This is made easy with OpenBSD’s rc system control, first enable and then start the dameons:

# rcctl enable smbd nmbd
# rcctl start smbd nmbd

macOS Client Setup

In Finder, open the Go menu and select Connect to server... or use the hotkey command-K then enter your server IP or hostname and shared location into the Server Address field:

smb://serveraddress/fileshare

Another dialog box will appear requiring your username and password; once entered, hit connect and you’re all set!