List and define SMB shares from command-line

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?


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.


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


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