返回

用 brew 安装 samba 替换系统的文件共享

之前都是用系统默认的文件共享系统在局域网内共享文件,但是在某次系统更新后用匿名用户就登陆不了了,即使将权限设置成任何人为「读与写」也不行了,然后就用 brew 安装了一个 samba 来替换原来的,也可以自定义 smb.conf,很方便。

  • 安装 samba
brew install samba
  • 禁用 netbiosd
sudo launchctl stop com.apple.netbiosd
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.netbiosd.plist
  • 创建启动项 org.samba.nmbd.plist 和 org.samba.smbd.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>Label</key>
    <string>org.samba.nmbd</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/Cellar/samba/3.6.20/sbin/nmbd</string>
        <string>-D</string>
    </array>
    <key>OnDemand</key>
    <false/>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>ServiceDescription</key>
    <string>netbios</string>
</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>Label</key>
    <string>org.samba.smbd</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/Cellar/samba/3.6.20/sbin/smbd</string>
        <string>-D</string>
    </array>
    <key>OnDemand</key>
    <false/>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>ServiceDescription</key>
    <string>samba</string>
</dict>
</plist>
  • 将 org.samba.nmbd.plist 和 org.samba.smbd.plist 移动至 /Library/LaunchAgents/

  • 创建启动项

sudo launchctl load -w /Library/LaunchAgents/org.samba.nmbd.plist
sudo launchctl load -w /Library/LaunchAgents/org.samba.smbd.plist
  • 照着 这里 配置后顺利共享