Skip to content

Instantly share code, notes, and snippets.

@jbfriedrich
Last active April 25, 2024 14:58
Show Gist options
  • Star 79 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save jbfriedrich/49b186473486ac72c4fe194af01288be to your computer and use it in GitHub Desktop.
Save jbfriedrich/49b186473486ac72c4fe194af01288be to your computer and use it in GitHub Desktop.
macOS 11.2 NSMB configuration
# /etc/nsmb.conf - macOS 11.3 - 2021-04-29
#------------------------------------------------------------------------------
# SMB configuration for macOS 11.3 <-> Synology
#------------------------------------------------------------------------------
# Additional information:
# -----------------------
# https://support.apple.com/de-de/HT211927
# https://support.apple.com/en-us/HT208209
# https://apple.stackexchange.com/questions/309016/smb-share-deadlocks-since-high-sierra
# https://photographylife.com/afp-vs-nfs-vs-smb-performance
# https://support.apple.com/de-de/HT212277
#------------------------------------------------------------------------------
[default]
# Use NTFS streams if supported
streams=yes
# Soft mount by default
soft=yes
# Disable signing due to macOS bug
signing_required=no
# Disable directory caching
dir_cache_off=yes
# Lock negotiation to SMB2/3 only
# 7 == 0111 SMB 1/2/3 should be enabled
# 6 == 0110 SMB 2/3 should be enabled
# 4 == 0100 SMB 3 should be enabled
protocol_vers_map=6
# No SMB1, so we disable NetBIOS
port445=no_netbios
# Turn off notifications
notify_off=yes
# SMB Multichannel behavior
# To disable multichannel support completely uncomment the next line
# mc_on=no
# Some Wi-Fi networks advertise faster speeds than the connected wired network.
mc_prefer_wired=yes
@jamietshaw
Copy link

Just found this via Google. Is the point of this to improve transfer speed?

@jjaarddev
Copy link

To speed up SMB file browsing, you can prevent macOS from reading .DS_Store files on SMB shares. This makes the Finder use only basic information to immediately display each folder's contents in alphanumeric order.
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE # log out of your macOS account and log back in to apply

also some stuff which can be useful:

# reload SMB deamon/process
sudo launchctl kickstart -k system/com.apple.smbd  # restart the SMB service without stopping and starting it separately
sudo launchctl stop com.apple.smbd ; sudo launchctl start com.apple.smbd

# restart SMB service
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.smbd.plist  # stop the SMB service
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist  # start the SMB service

#---------------------------------------------------------------------------

# remove all extended attributes of the shared directory. Either one by one using something like:
xattr /path/to/shared/dir
com.apple.FinderInfo
com.apple.metadata:_kMDItemUserTags
purgeable-drecs-fixed

xattr -d com.apple.metadata:_kMDItemUserTags /path/to/shared/dir
xattr -d purgeable-drecs-fixed /path/to/shared/dir
xattr -d com.apple.FinderInfo /path/to/shared/dir

# or all directly:
$ xattr -c /path/to/shared/dir

@jamietshaw
Copy link

Thank you

@neerajadsul
Copy link

Can't believe! It worked and finally resolved my issues with Unraid backup. Many thanks!

@asmaier
Copy link

asmaier commented Nov 28, 2023

Thank you for this nice config file. What has helped me in addition was to delete all ._-Files, all .DS_Store files', which have been left-over on the SMB share. They seem to confuse Mac OS X

find . -name "._*" -exec rm {} \;
find . -name ".DS_Store" -exec rm {} \;

But one question: Online I also found these additional options (see https://arstechnica.com/civis/threads/so-is-everyone-use-smb-now-to-connect-to-network-shares.1462201/ , https://www.reddit.com/r/macsysadmin/comments/c9t1co/what_your_nsmbconf_file_looks_like/ , https://macosblog.ch/2020/01/26/mac-os-als-smb-client-reloaded/)

aapl_off=false
file_ids_off=yes

dir_cache_async_cnt=0
dir_cache_max_cnt=0
dir_cache_max=0
dir_cache_min=0

Are these all obsolete?

@jbfriedrich
Copy link
Author

jbfriedrich commented Nov 28, 2023

I compiled the config file back in '21 based on the online resources I mention in the config file header. Sorry, no idea what is obsolete or not. I dont even use this file anymore, they got lost after an update and I never configured them again on newer macOS versions.

@jjaarddev
Copy link

Thank you for this nice config file. What has helped me in addition was to delete all ._-Files, all .DS_Store files', which have been left-over on the SMB share. They seem to confuse Mac OS X

find . -name "._*" -exec rm {} \;
find . -name ".DS_Store" -exec rm {} \;

But one question: Online I also found these additional options (see https://arstechnica.com/civis/threads/so-is-everyone-use-smb-now-to-connect-to-network-shares.1462201/ , https://www.reddit.com/r/macsysadmin/comments/c9t1co/what_your_nsmbconf_file_looks_like/ , https://macosblog.ch/2020/01/26/mac-os-als-smb-client-reloaded/)

aapl_off=false
file_ids_off=yes

dir_cache_async_cnt=0
dir_cache_max_cnt=0
dir_cache_max=0
dir_cache_min=0

Are these all obsolete?

It needs to be taken into account, that some parameters of SMB config are used/work on macOS and some not (but all work on Linux), so for example port mapping does not work in macOS, so my all (I use it in both macOS and Linux) parameters config file:

# https://support.apple.com/en-us/HT208209
# https://apple.stackexchange.com/questions/309016/smb-share-deadlocks-since-high-sierra
# https://photographylife.com/afp-vs-nfs-vs-smb-performance
# https://support.apple.com/de-de/HT212277
# /etc/nsmb.conf

# On LINUX sudo nano /etc/samba/smb.conf
#------------------------------------------------------------------------------



[default]

streams=yes  # Use NTFS streams if supported
soft=yes  # Soft mount by default
signing_required=no  # Disable signing due to macOS bug
dir_cache_off=yes  # Disable directory caching

# Lock negotiation to SMB2/3 only
# 7 == 0111  SMB 1/2/3 should be enabled
# 6 == 0110  SMB 2/3 should be enabled
# 4 == 0100  SMB 3 should be enabled
protocol_vers_map=4

smb_port=445,2082,2095  # enable custom ports (just for Linux)
port445=no_netbios  # No SMB1, so we disable NetBIOS
notify_off=yes  # Turn off notifications
# mc_on=no  # SMB Multichannel behavior, To disable multichannel support completely uncomment the next line 




# partameter                             default value

# nbtimeout               + + -          1s             Timeout for resolving a NetBIOS name
# minauth                 + + -          NTLMv2         Minimum authentication level allowed
# streams                 + + +          yes            Use NTFS Streams if server supported
# soft                    + + +          no             Force all mounts to be soft
# notify_off              + + +          no             Turn off using notifications
# kloglevel               + - -          0              Turn on smb kernel logging
# protocol_vers_map       + - -          7              Bitmap of SMB Versions that are enabled
# signing_required        + - -          no             Turn on smb client signing
# signing_req_vers        + - -          6              Bitmap of SMB Versions that have signing required
# validate_neg_off        + - -          no             Turn off using validate negotiate
# max_resp_timeout        + + -          30s            Max time to wait for any response from server
# submounts_off           + + +          no             Turn off using submounts
# dir_cache_async_cnt     + + -          10             Max async queries to fill dir cache
# dir_cache_max           + + -          60s            Max time to cache for a dir
# dir_cache_min           + + -          30s            Min time to cache for a dir
# max_dirs_cached         + + -          Varies         Varies from 200-300 depending on RAM amount
# max_cached_per_dir      + + -          Varies         Varies from 2000-10000 depending on RAM amount
# netBIOS_before_DNS      + + +          no             Try NetBIOS resolution before DNS resolution
# mc_on                   + - -          yes            Turn on SMB multichannel (allow more than one channel per session)
# mc_prefer_wired         + - -          no             Prefer wired NIC's over wireless in multichannel mode - Some Wi-Fi networks advertise faster speeds than the connected wired network. 
# encrypt_cipher_map      + - -          15             Bitmap of SMB 3.1.1 encryption algorithms that are enabled
# force_sess_encrypt      + - -          no             Force session encryption for all mounts
# force_share_encrypt     + - -          no             Force share encryption for all mounts


[user-name]
  comment = user-name home folder
  path = /home/user-name
  browseable = yes
  valid users = jjaard
  create mask = 0775
  directory mask = 0775
  force user = sambauser
  force group = users
  read only = No
  guest ok = No


#---------------------------------------------------------------------------

# reload SMB deamon/process
sudo launchctl kickstart -k system/com.apple.smbd  # restart the SMB service without stopping and starting it separately
sudo launchctl stop com.apple.smbd ; sudo launchctl start com.apple.smbd

# restart SMB service
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.smbd.plist  # stop the SMB service
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist  # start the SMB service





#---------------------------------------------------------------------------

# remove all extended attributes of the shared directory. Either one by one using something like:
xattr /path/to/shared/dir
com.apple.FinderInfo
com.apple.metadata:_kMDItemUserTags
purgeable-drecs-fixed

xattr -d com.apple.metadata:_kMDItemUserTags /path/to/shared/dir
xattr -d purgeable-drecs-fixed /path/to/shared/dir
xattr -d com.apple.FinderInfo /path/to/shared/dir

# or all directly:
$ xattr -c /path/to/shared/dir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment