bash 如何在 Mac OS X 上从终端启用用户帐户 SMB 共享?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7824946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to enable User Account SMB sharing from terminal on Mac OS X?
提问by User1234
I'm trying to enable Account Sharingfrom terminal. I can't figure out how to do that.
我正在尝试从终端启用帐户共享。我不知道该怎么做。
This will be used from inside an application I'm currently programming. The application creates a hidden user, then should enable SMB sharing for this user. Later, I need to connect to this share via another server using SMB.
这将从我当前正在编程的应用程序内部使用。应用程序创建一个隐藏用户,然后应该为该用户启用 SMB 共享。稍后,我需要使用 SMB 通过另一台服务器连接到此共享。
I need the same effectas going to System Preferences → Sharing → File Sharing →enable any account for sharing using SMB.
我需要与进入系统偏好设置 → 共享 → 文件共享 →启用任何使用 SMB 共享的帐户相同的效果。


What I already have:
我已经拥有的:
- I know how to create a hidden user
- I already know how to create individual shared folders, but not account sharing.
- 我知道如何创建隐藏用户
- 我已经知道如何创建个人共享文件夹,但不知道如何共享帐户。
What I've already tried:
我已经尝试过的:
- I already tried to scan the system for last modified files to find some information in Samba config files, but it didn't help.
- 我已经尝试扫描系统以查找上次修改的文件以在 Samba 配置文件中找到一些信息,但没有帮助。
What I don't need:
我不需要的东西:
- I can't do this with SSH. The folders needto be shared via SMB.
- 我不能用 SSH 做到这一点。文件夹需要通过 SMB 共享。
采纳答案by User1234
THIS WORKS FOR OS X 10.5, 10.6, 10.7
这适用于 OS X 10.5、10.6、10.7
First type this in terminal
首先在终端输入这个
pwpolicy -u SomeUser -sethashtypes SMB-NT on
SomeUsercan also be hidden, it doesn't matter. This gives the same effect like enabling that checkbox as shown in the picture above.
SomeUser也可以隐藏,没关系。这提供了与启用该复选框相同的效果,如上图所示。
After that:
在那之后:
dscl . -passwd /Users/SomeUser "UserPassword"
This gives the same effect, as enabling it from System Preferences, when it asks for a password. It's the same like filling in that password.
当它要求输入密码时,这与从系统偏好设置启用它的效果相同。就像填写那个密码一样。
If you want to disable SMB on that account (SomeUsercan be hidden again):
如果您想在该帐户上禁用 SMB(SomeUser可以再次隐藏):
pwpolicy -u SomeUser -sethashtypes SMB-NT off
P.S. In Mac OS X Lion, they changed their implementation for SMB (SMBX). But be aware that it still uses the same Share Points mechanism for creating a share, and Directory Service is responsible for it. Also it still works the same way for enabling SMB on account!
PS 在 Mac OS X Lion 中,他们更改了 SMB (SMBX) 的实现。但请注意,它仍然使用相同的 Share Points 机制来创建共享,并且 Directory Service 负责它。此外,它仍然以相同的方式启用 SMB 帐户!
回答by DNax
I've tried the answer above in 10.7 and I was happy to see that after the SMB-NT on, the setting appeared effectively on in the Sharing Options screen.
我已经在 10.7 中尝试了上面的答案,我很高兴看到在 SMB-NT 开启后,该设置有效地出现在“共享选项”屏幕中。
The problem is that being that user enabled with that method I could not connect from Windows. So I had to try another esoteric solution that I had found before and I didn't want to try:
问题是,作为启用该方法的用户,我无法从 Windows 连接。所以我不得不尝试我之前找到的另一个深奥的解决方案,我不想尝试:
- Is about changing the /var/db/dslocal/nodes/Default/users/.plist file reordering the authentication_authority array values.
- 是关于更改 /var/db/dslocal/nodes/Default/users/.plist 文件重新排序 authentication_authority 数组值。
Here is the full explanation: https://discussions.apple.com/thread/3211072?start=0&tstart=0
这是完整的解释:https: //discussions.apple.com/thread/3211072?start=0&tstart=0
After making that change, the user smb setting was again OFF (maybe because I used a .plist old file), but I was able to effectively turn it ON and to connect from Windows!
进行更改后,用户 smb 设置再次关闭(可能是因为我使用了 .plist 旧文件),但我能够有效地将其打开并从 Windows 连接!
回答by Mohanraj N
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
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist
sudo 默认写入 /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist EnabledServices -array disk
This could be one other way.
这可能是另一种方式。
And to disable it again, - unload it.
并再次禁用它, - 卸载它。
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.smbd.plist
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.smbd.plist

