Skip to content

Instantly share code, notes, and snippets.

@oceanyeo
Last active November 30, 2022 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oceanyeo/949a91fee4f81675817848ceba4e4bc7 to your computer and use it in GitHub Desktop.
Save oceanyeo/949a91fee4f81675817848ceba4e4bc7 to your computer and use it in GitHub Desktop.
Install Samba4 with Homebrew

Install Samba4 with Homebrew

brew install samba

Config

I created directories for sharing at /Users/SharedFolder

I created my samba config at /usr/local/etc/smb.conf (default path)

# /usr/local/etc/smb.conf

[global]
server string = Samba Server Version %v
security = user
passdb backend = tdbsam:/usr/local/etc/passdb.tdb
map to guest = Bad user

[SharedFolder]
path = /Users/SharedFolder

valid users = share
write list = share 

Create a user in System Preferences -> Users & Groups named share. It can be a Sharing Only user rather than Standard or Administrator.

Make sure that the share user owns the SharedFolder directory

Samba users must be real users on your system. You cannot make up fake users. That is why we created the share. share is explicitly for authenticating against our system over Samba

You can set a Samba password for the share like so.

smbpasswd -a share

Set Samba up to launch on boot

curl -s https://gist.githubusercontent.com/oceanyeo/949a91fee4f81675817848ceba4e4bc7/raw/setup.sh | bash
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.samba.nmbd</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/nmbd</string>
<string>-s</string>
<string>/usr/local/etc/samba/smb.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
<?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">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.samba.smbd</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/samba-dot-org-smbd</string>
<string>-s</string>
<string>/usr/local/etc/samba/smb.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
#!/usr/bin/env bash
function unloadctl(){
label=$1
sudo launchctl list | grep ${label} > /dev/null
if (($? == 0));then
sudo launchctl stop ${label}
sudo launchctl unload -w /System/Library/LaunchDaemons/${label}.plist
fi
}
function loadctl(){
label=$1
sudo launchctl list | grep ${label} > /dev/null
if (($? == 0));then
sudo launchctl stop ${label}
sudo launchctl unload -w /Library/LaunchDaemons/${label}.plist
fi
sudo launchctl load -w /Library/LaunchDaemons/${label}.plist
sudo launchctl start ${label}
}
# disable system netbiosd-daemon
unloadctl 'com.apple.netbiosd'
# disable system samba-daemon
unloadctl 'com.apple.smbd'
# the directory smbd will use for storing such files as smbpasswd and secrets.tdb.
custom_private_dir=/usr/local/etc/samba
if [[ ! -d $custom_private_dir ]];then
sudo mkdir -p $custom_private_dir/private
fi
curl -O -sS https://gist.githubusercontent.com/oceanyeo/949a91fee4f81675817848ceba4e4bc7/raw/smb.conf
sudo mv -f $(pwd)/smb.conf $custom_private_dir
# install new samba into launchd
curl -O -sS https://gist.githubusercontent.com/oceanyeo/949a91fee4f81675817848ceba4e4bc7/raw/org.samba.smbd.plist
sudo mv $(pwd)/org.samba.smbd.plist /Library/LaunchDaemons/
sudo chown root:wheel /Library/LaunchDaemons/org.samba.smbd.plist
curl -O -sS https://gist.githubusercontent.com/oceanyeo/949a91fee4f81675817848ceba4e4bc7/raw/org.samba.nmbd.plist
sudo mv $(pwd)/org.samba.nmbd.plist /Library/LaunchDaemons/
sudo chown root:wheel /Library/LaunchDaemons/org.samba.nmbd.plist
loadctl 'org.samba.smbd'
loadctl 'org.samba.nmbd'
# set smb password for the share user
sudo smbpasswd -c "${custom_private_dir}/smb.conf" -a share
# /usr/local/etc/samba/smb.conf
[global]
workgroup = WORKGROUP
server string = Samba Server Version %v
security = user
passdb backend = tdbsam
map to guest = Bad user
private dir = /usr/local/etc/samba/private
vfs objects = fruit streams_xattr
fruit:metadata = stream
fruit:model = MacSamba
fruit:posix_rename = yes
fruit:veto_appledouble = no
fruit:nfs_aces = no
fruit:wipe_intentionally_left_blank_rfork = yes
fruit:delete_empty_adfiles = yes
fruit:time machine = yes
[SharedFolder]
path = /Users/SharedFolder
valid users = share
write list = share
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment