💻 macOSのSMBを早くする方法

redditで話題に上がってたのでご紹介

macOSのSMBをカスタマイズする実行ファイル

ソース元では正常に動作しなかったので改変しています

#!/bin/bash

# Check if script is run with sudo
if [ "$EUID" -ne 0 ]; then 
    echo "Please run as root (use sudo)"
    exit 1
fi

# Commands that decrease security

# Check if the nsmb.conf file exists and remove it if it does
if [ -f /private/etc/nsmb.conf ]; then
    rm /private/etc/nsmb.conf
fi

# Create a new nsmb.conf file with default section
echo "[default]" > /etc/nsmb.conf

# Disable SMB signing (decreases security)
echo "signing_required=no" >> /etc/nsmb.conf

# Remove validate_neg_off as it's not needed in recent versions
# echo "validate_neg_off=yes" >> /etc/nsmb.conf

# End Section

# Commands with neutral or mixed impact on security

# Enable support for named streams (neutral)
echo "streams=yes" >> /etc/nsmb.conf

# Disable change notifications (neutral, but might affect operational efficiency)
echo "notify_off=yes" >> /etc/nsmb.conf

# Enable soft mounts (neutral, but could impact data availability)
echo "soft=yes" >> /etc/nsmb.conf

# Disable directory caching (neutral, but impacts performance)
echo "dir_cache_max_cnt=0" >> /etc/nsmb.conf
echo "dir_cache_max=0" >> /etc/nsmb.conf
echo "dir_cache_off=yes" >> /etc/nsmb.conf

# End Section

# Commands that improve or do not affect security significantly

# Disable NetBIOS and use direct hosting over TCP/IP (improves security)
echo "port445=no_netbios" >> /etc/nsmb.conf

# Set SMB protocol version to SMB 2 or later (improves security)
echo "protocol_vers_map=6" >> /etc/nsmb.conf

# Enable multi-channel support and prefer wired connections (neutral, typically safe)
echo "mc_on=yes" >> /etc/nsmb.conf
echo "mc_prefer_wired=yes" >> /etc/nsmb.conf

# Prevent creation of .DS_Store files on network shares (neutral, improves performance)
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE

# End Section

# Exit script
exit
mac-smb.sh

これを実行するだけですが、自己責任でお試しを!

sudo bash mac-smb.sh

また、変更後にSMB接続がうまくいかない場合は、以下も試してみてください:

  1. SMBサービスの再起動:
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.smbd.plist
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist
  1. キャッシュのクリア:
sudo killall -HUP mDNSResponder

デフォルトに復元

macOSの標準設定に戻したい場合は、下記を実行

rm /private/etc/nsmb.conf; defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool FALSE; exit