Enable SMB sharing from command line
On OS X 10.8, using terminal commands, I'd like to enable SMB sharing as if I had ticked the following checkbox under System Preferences - Sharing - File Sharing - Options
:
I've tried the following command:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist
But despite the smb daemon seeming to be up and running, the checkbox is still unchecked, as if something is missing.
The same command works, as an example, for screen sharing (com.apple.screensharing.plist
) and even for AFP (com.apple.AppleFileServer.plist
), only SMB seem to suffer from this problem.
Solution 1:
I've found the solution. Two commands are needed in sequence:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist EnabledServices -array disk
Solution 2:
For others who might be having this same issue with a different root cause, I found that somehow my com.apple.smbd.plist
file had gotten corrupt.
You can check this with cat /System/Library/LaunchDaemons/com.apple.smbd.plist
.
It should appear to be plain text, but if you see a bunch of weird characters, it's probably corrupt.
I simply deleted the file [and after realizing it did not get recreated on reboot] copied my com.apple.smbd.plist
from another Mac into /System/Library/LaunchDaemons/
. Then I checked the checkbox (or alternately, you could run sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist
), and then rebooted.
Problem solved. Same issue, different root cause.
Edit: You should also verify permissions on com.apple.smbd.plist
and com.apple.AppleFileServer.plist
, especially if copying from a different computer. I discovered that my com.apple.AppleFileSharing.plist
file had 777
permission, which was causing it not to load.
Ownership should be root:wheel
, and permissions should be 644
:
sudo chown root:wheel /System/Library/LaunchDaemons/com.apple.smbd.plist
sudo chown root:wheel /System/Library/LaunchDaemons/com.apple.AppleFileServer.plist
sudo chmod 644 /System/Library/LaunchDaemons/com.apple.smbd.plist
sudo chmod 644 /System/Library/LaunchDaemons/com.apple.AppleFileServer.plist