The pain of getting SMB file sharing working on Mac.
A little history
There’s quite a bit of history to running SMB file sharing on OSX. My understanding of the history is that SAMBA was originally MIT or BSD licensed — and Apple used it. Then SAMBA went GPL licensed and Apple had to develop their own SMB code. Oh dear, oh dear!
After trying Apple’s Server product on a Mac mini, and failing, I ended up using Homebrew to compile SAMBA.
This ran absolutely wonderfully, using SMB v1, all the while we had WinXP. The Mac mini, coupled with TimeMachine, proved a great choice.
Eventually, though Microsoft made it harder to enable SMB v1, then impossible. So, it was time to upgrade…
After a week or so of fishing around, it became evident that SAMBA was not going to be a simple MacPorts or Homebrew experience.
I ended up installing VirtualBox, with Ubuntu Server doing the SAMBA part. By matching up the UIDs within the Ubuntu machine with the Mac mini’s UIDs of the data to be served it all worked pretty well. The shared area was living in the OSX domain (so that it was TimeMachined), and a VirtualBox shared folder provided a helpful gateway for the Ubuntu server to access and deliver the files.
But Ubuntu crashed about every week or two… and then the VM drive would be mounted in read-only mode… so ‘fsck’ to the rescue (mostly). Until ‘fsck’ didn’t work because the file system had been scrubbed so badly.
TimeMachine managed to save the day — I restored the VM disk and got Ubuntu working again. But it was time to ditch it. I do not have time to baby sit an unreliable server.
This link provided a really good starting point:
Compiling and Running Samba 4 Server on macOS
The goal of this article is to compile and run a Samba server on a Mac using the open source version of Samba instead…
I strongly recommend you use that page as a reference as I’m going to highlight the additional steps.
Getting SAMBA to work on High Sierra was not very straightforward. Here are my observations to getting it to work in 2019.
First, download Xcode from the App Store.
Then, install the command line bits:
xcode-select -switch /Applications/Xcode.app
Maybe there’s an easier way, but this got things working for me :-)
Downloading and Configuring SAMBA
This first part is the same as Will’s page…
git clone https://git.samba.org/samba.git
Change into the
Check out the latest version that works with this process:
git checkout samba-4.8.9
I just couldn’t get later versions building on OSX. Dependencies have changed, and it just got too messy.
Configure SAMBA to be installed at
(Be prepared for a long wait!)
As mentioned on Will Haley’s article, download the
nss.diff patch ( this tiny diff/patch file as nss.diff )and apply it, running this command from the
git apply ~/path/to/nss.diff
I found that SAMBA would build and run from this point, but ended up with constant authentication errors when trying to connect to the SAMBA server. Nothing worked as it should.
After many unsuccessful attempts, I worked through the verbose debug logs and finally worked out that the error
failed to get the unix group list was the key to the problem.
A little Googling (actually much more than a little!) came to https://trac.macports.org/ticket/35568 and the patch listed at https://attachments.samba.org/attachment.cgi?id=7727
The patch is different for SAMBA 4.8.9, but the key element of
max_grp = 128 being the same.
The file that needs editing is in
Look for the function
get groups_unix_user (line 204).
Make the following change:
int max_grp = 128;
int max_grp = MIN(128, groups_max());
Now that the patches have been applied you can build:
make && sudo make install
I’d suggest you take a look at Will Haley’s article for a starting point.
Also ensure you setup the OSX users — because they have to exist — and use the
smbpasswd tool to create the appropriate entries for SAMBA.
Before you launch into creating a
LaunchDaemon, do use the debug command:
sudo /opt/samba/sbin/smbd \
To kill the SAMBA process, use Activity Monitor, look for the
smbd processes — and find the one with the lowest PID number. Then force-quit that process and you’ll get the command prompt back. (Or you could just close the terminal session).
Once it’s all working nicely you can create a plist file in
/Libray/LaunchDaemons to auto-start SAMBA on boot.
I just called mine
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
You’ll need to
sudo chown root:wheel homebrew.samba.plist and then install:
sudo launchctl load /Library/LaunchDaemons/homebrew.samba.plist
sudo launchctl start homebrew.samba
Increasing File Limits on the server
Even though this initially worked, I found that some apps were failing to open files. An hour or two of researching uncovered file limits in Mavericks and beyond.
Shows only 256 open files!
Following this link: https://blog.dekstroza.io/ulimit-shenanigans-on-osx-el-capitan/
csr (using Recovery mode Terminal), added the
limits.maxproc.plist files. Finally,
ulimit -a shows 524288 max files, and the apps now seem to function correctly.
I really wish someone else had fried their brain on my behalf… I apologise if I’ve missed out any steps. This was completed over a course of many, many weeks (interleaving with other ‘real’ work).
Now we have a very fast Mac mini SAMBA server that’s running entirely from a USB 3 Samsung T5 1TB storage that’s serving an office of Windows 10 and Mac machines.
Let me know if I’ve slipped up anywhere, or if this process has helped you out.
Please let me know the comments about your successes and failures… for me this has been running wonderfully well for some weeks. Maybe someone could bring these tweaks to Homebrew?