Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable User Account SMB sharing from terminal on Mac OS X?

I'm trying to enable Account Sharing from 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.

I need the same effect as going to System Preferences → Sharing → File Sharing → enable any account for sharing using SMB.

enter image description here


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.

What I don't need:

  • I can't do this with SSH. The folders need to be shared via SMB.
like image 820
User1234 Avatar asked Oct 08 '11 20:10

User1234


People also ask

How do I enable Samba on Mac?

On your Mac, choose Apple menu > System Preferences, then click Sharing . Select the File Sharing tickbox, then click Options. Select “Share files and folders using SMB”.

How do I Share files from Mac to Windows network?

Set up file sharing on the MacClick Options. Select “Share files and folders using SMB”. In the Windows File Sharing list, select the tickbox next to the user account that will be used to share files with Windows users, enter the password for that user, then click OK. Click Done, then click Done.


2 Answers

THIS WORKS FOR OS X 10.5, 10.6, 10.7

First type this in terminal

pwpolicy -u SomeUser -sethashtypes SMB-NT on

SomeUser can also be hidden, it doesn't matter. This gives the same effect like enabling that checkbox as shown in the picture above.

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 (SomeUser can be hidden again):

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!

like image 61
User1234 Avatar answered Sep 21 '22 00:09

User1234


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.

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:

  • Is about changing the /var/db/dslocal/nodes/Default/users/.plist file reordering the authentication_authority array values.

Here is the full explanation: 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!

like image 23
DNax Avatar answered Sep 21 '22 00:09

DNax