When remotely troubleshooting an issue on a client recently, I had produced some log files that I wanted to extract. As I couldn't remember off the top of my head how to mount a network share from the Terminal, I decided to look into how to create a local share point that I could access via SMB. It turns out it that it's quite (very) simple.

On macOS, the default Sharing settings are:

File Sharing from the Terminal 01

To setup a local share on this client, I did the following:

  • Created the directory I intended to share:
mkdir -p /Users/Shared/my-shared-folder  
  • Enabled File Sharing:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist
  • Shared the folder:
sudo sharing -a /Users/Shared/my-shared-folder

Following that, Sharing would look like this:

File Sharing from the Terminal 02

And you'd be able to mount your share via smb://hostname/my-shared-folder. Easy.

To revert these changes:

  • Unshare the folder:
sudo sharing -r my-shared-folder
  • Disable File Sharing:
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.smbd.plist
  • Remove the directory
rm -rf /Users/Shared/my-shared-folder

That's it!