keepcalculator

06 Numbers and Powers

Mount SMB Share Command Line Mac

Card No. 06·84932 · Updated · Standard formula, shown below

To mount an SMB share from the Mac command line, use the mount_smbfs command followed by the server URL and a local mount point. For example, mount_smbfs //user@server/share /Volumes/mountpoint connects to the share and makes it available at the specified directory. This guide explains the full syntax, common options, troubleshooting, and how to automate the process.

Understanding mount_smbfs

mount_smbfs is the built-in macOS utility that mounts SMB (Server Message Block) network shares, the protocol used by Windows, macOS, and many NAS devices. It is the command-line equivalent of the Finder’s “Connect to Server” (Cmd+K) feature. The basic syntax is:

mount_smbfs [options] //[domain;][user[:password]@]server[/share] /mount/point

The URL format is crucial: it starts with //, optionally includes a domain, user, and password, then the server name or IP, and the share name. If you omit the share, the server’s default share list is shown. The mount point must already exist as an empty directory, typically created with mkdir.

Basic Usage Examples

Here are a few practical examples to get started:

  • Mount with current user: mount_smbfs //server/share /Volumes/share – uses your macOS username and prompts for a password.
  • Mount with a specific user: mount_smbfs //john@server/share /Volumes/share – connects as user “john”.
  • Mount with domain: mount_smbfs //WORKGROUP;john@server/share /Volumes/share – specifies a Windows domain.
  • Mount with password in command: mount_smbfs //john:password@server/share /Volumes/share – not recommended for security, but works.

After mounting, you can access the files at the mount point. Use umount /Volumes/share to disconnect.

Common Options and Flags

mount_smbfs supports several options that control how the share is mounted. Some of the most useful include:

  • -N – Do not prompt for a password. Useful for guest access or when the password is in the URL.
  • -o – Mount options like ro (read-only) or rw (read-write). For example, -o ro mounts read-only.
  • -d – Set the directory mode (permissions) for the mount point, e.g., -d 755.
  • -f – Set the file mode, e.g., -f 644.
  • -s – Use the server’s name for the mount point instead of the share name.
  • -w – Specify the workgroup (domain) separately.

For a complete list, run man mount_smbfs in the terminal.

How to Choose the Right Approach

The command line is ideal when you need to mount shares in scripts, automate backups, or manage servers without using the GUI. If you only need a one-off connection, the Finder is simpler. However, for repeated or scheduled tasks, the command line offers precision and reproducibility. Consider using mount_smbfs when:

  • You’re writing a shell script that needs to access network files.
  • You’re managing multiple servers and want to standardize mount commands.
  • You need to mount a share with specific options (read-only, no password prompt) that are cumbersome to set in the Finder.

For casual use, the Finder’s “Connect to Server” (Cmd+K) is more user-friendly and remembers recent connections.

Common Problems and Troubleshooting

Several issues can arise when mounting SMB shares from the command line. Here are the most frequent ones and how to fix them:

  • “Mount point does not exist” – Create the directory first with mkdir /Volumes/share.
  • “Permission denied” – Check that the user has access to the share on the server. You may need to specify a domain or use the correct credentials.
  • “Connection refused” – The server may be down, or the SMB port (445) is blocked. Verify the server address and network connectivity.
  • Password prompt not appearing – Use -N to skip the prompt, or include the password in the URL (though insecure).
  • Mount hangs – Try using the server’s IP address instead of the hostname, or add -o timeout=30 to limit the wait.

If you get an error like mount_smbfs: server connection failed, check that the share name is correct and that the server allows SMB connections.

Automating Mounts with Scripts

One of the main advantages of the command line is automation. You can create a shell script that mounts a share, performs operations, and unmounts it. Here’s a simple example:

#!/bin/bash
mkdir -p /Volumes/projects
mount_smbfs //user@server/projects /Volumes/projects
# ... do work ...
umount /Volumes/projects

To avoid password prompts in scripts, you can use a keychain or store the password in a secure environment variable. A common pattern is to read the password from a file or use security to retrieve it from the Keychain. For example:

PASS=$(security find-internet-password -s server -a user -w)
mount_smbfs //user:$PASS@server/share /Volumes/share

This keeps the password out of the script itself.

Security Considerations

When using mount_smbfs, be mindful of security. Avoid embedding passwords in plain text in scripts or command lines, as they can be seen in process lists and shell history. Use the Keychain or prompt for passwords interactively. Also, be aware that SMB traffic is not encrypted by default in older protocols. Modern macOS and Windows support SMB 3.0, which includes encryption, but ensure both ends support it. For sensitive data, consider using SSHFS or other encrypted file transfer methods.

Frequently Asked Questions

How do I mount an SMB share without a password?

Use the -N option to suppress the password prompt, and if the server allows guest access, you can mount with mount_smbfs -N //server/share /Volumes/share. If the share requires a user, you’ll need to provide credentials.

Can I mount an SMB share automatically at login?

Yes, you can add the mount command to your Login Items (System Settings > Users & Groups > Login Items) or create a LaunchAgent. A LaunchAgent plist can run a script that mounts the share when you log in.

Why does mount_smbfs say “mount point does not exist”?

The directory you’re trying to mount to must already exist. Create it with mkdir before running mount_smbfs. For example, mkdir -p /Volumes/myShare.

How do I unmount an SMB share from the command line?

Use the umount command followed by the mount point: umount /Volumes/myShare. If the share is busy, you may need to use diskutil unmount /Volumes/myShare which forces the unmount.

What is the difference between mount_smbfs and mount -t smbfs?

mount_smbfs is the dedicated wrapper for SMB on macOS. mount -t smbfs is a more generic mount command that also works, but mount_smbfs provides SMB-specific options and is the recommended tool.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →