6

In MacOS, is it possible to list and/or define SMB shares at the command-line?

On a Linux machine with Samba, I can use the testparm command and the /etc/samba/smb.conf file.

On Windows it would be the net share ... command.

On Mac, I only know the "System Preferences" > "Sharing" GUI. But to check or set these shares on multiple machines, I would like to be able to do it through SSH sessions and the command-line.

Is this possible?

3 Answers 3

10

On macOS open Terminal and type man sharing to review the manual page. You can use sharing -l to list AFP/SMB share info. You can add and remove shares using this command line tool.

You can use the df -h command or mount command to list externally mounted volumes & shares.

1
  • Works great on corporate laptops where you cannot manage shared folders from the Settings app, but have sudo :)
    – Ahi Tuna
    May 3 at 13:41
3

There's is a utility called smbutil that can be used to view SMB shares

For example:

% smbutil view -G //servername.domain

Will display the shares that are available via guest access

2
  • That lists locally mounted remote shares, not local directories which are shared.
    – mivk
    Nov 3, 2020 at 15:36
  • 1
    Oh..you want local directories...I mis-read it. sharing -l is the answer.
    – Allan
    Nov 3, 2020 at 15:40
2

As suggested in James Brickley's answer, there is indeed the (well hidden) sharing command.

It can be used for both listing and managing shares.

To list shares:

sharing -l

To create a share:

sudo sharing -a /Volumes/SomeDisk 

or, for example to share only over SMB (not AFP), and give the share a different name (here "X_SomeDisk") :

sudo sharing -a /Volumes/SomeDisk -S X_SomeDisk -n X_SomeDisk -s 001

To remove the share created above:

sudo sharing -r X_SomeDisk

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .