3

If I use Finder's ⌘K shortcut, I can mount SMB shares as my normal MacOS user. A mount point is created in /Volumes, and the mount point will be owned by the user I'm logged in as.

But there are limitations to this approach. One limitation is that Finder will only let you use one account on the remote system. In other words, If I have access to two home directories under different accounts on the same SMB server, I can't mount them both with Finder.

But I can mount them both from the command line. The command is:

mount -t smbfs //user@host/target mount-point

You should be able to just run this command as your normal user and the resulting mount would be owned by that user. Someone claims success doing this here.

Someone else had the same problem as me, but with a different error, here. The solutions provided then don't work now.

And all of this works fine when mounting a share being served by Windows.

But if I want to mount a share being served by Samba, I have to either be logged in as root (in which case the mount will succeed but the filesystem will be owned by root), or I have to use Finder.

If I run mount as my normal user, the error I depends on if the mount point exists or not.

If it does:

macbook:~ user$ mount -t smbfs //user@linuxhost/remote-path local-path
Password for host: 
mount_smbfs: mount error: /Users/user/local-path: File exists
mount: /Users/user/local-path failed with 64

If it doesn't:

macbook:~ user$ rmdir local-path
macbook:~ user$ mount -t smbfs //user@linuxhost/remote-path local-path
mount: realpath /Users/user/local-path: No such file or directory

The File exists error is not caused by the SMB share already being mounted.

What difference between Samba and Windows might mount_smbfs be picking up on that triggers this problem?

3 Answers3

1

On my system - macOS Catalina this works:

Mount an smbfs/cifs drive manually:

1. Preferred: use mount -t filesystem spec

% mount -t smbfs //username:userpasswd@ServerName/ShareName /Users/username/mount-point

For example:

% mount -t smbfs //seamus:mysecret@SynologyNAS-1/backups /Users/seamus/rsync_dest

2. Also seems to work using mount_smbfs directly:

% mount_smbfs //seamus:mysecret@SynologyNAS-1/backups /Users/seamus/rsync_dest/ 

3. Troubleshooting

If these don't work, there are some alternatives worth looking into:

  • Instead of using the hostname (e.g. SynologyNAS-1), use the host's IP address instead.

  • The SMB protocol has a checkered past. You may have different versions on your client, and your server, and they will negotiate to select the "best" one. However, SMB ver 1 was so bad - so insecure - that it is generally blacklisted in modern implementations; i.e. a client may refuse to connect to a server that's limited to SMB ver 1, and vice-versa. In my experience, Apple's mount_smbfs does not seem to blacklist SMB ver 1 servers, but macOS is rather opaque, and there may be other things afoot; i.e. it's worth a look. The mount command has a -v (verbose) option that may give some useful clues.

Some points in the documentation:

  • Refer to man mount_smbfs for a list of the options

man mount_smbfs says:

At run time, mount_smbfs reads the ~/Library/Preferences/nsmb.conf file for additional configuration parameters and a password.

There is also a man nsmb.conf which says:

/etc/nsmb.conf The global configuration file.
~/Library/Preferences/nsmb.conf
The user's configuration file, conflicts will be overwritten by the global file

HOWEVER: neither /etc/nsmb.conf, nor ~/Library/Preferences/nsmb.conf exist on my system. Nevertheless, both the above commands cause my system to mount the drive. "The drive" is a Synology NAS, and the share is SMB.

Seamus
  • 4,547
  • You're doing the same thing I'm doing, the only difference being it works on your system and it doesn't work on mine. nsmb.conf is absent on my system also. There's one other difference: You're putting the password directly in the URL, while I'm letting mount_smbfs prompt me for it. I get the error mount_smbfs: URL parsing failed, please correct the URL and try again: Invalid argument if I try putting the password in the URL. I just realized that mount_smbfs has its own version number: 3.4.4 on my system. – Throw Away Account Jul 31 '22 at 06:51
  • I wonder if getting a newer version of mount_smbfs would help. It's apparently open-source, but I can't get Google to show me where I can download the complete build tree. – Throw Away Account Jul 31 '22 at 06:51
  • @ThrowAwayAccount: My system (Catalina) also uses mount_smbfs: version 3.4.4. Your error message suggests that it can't resolve your hostname (host?? :). You should try to use its IP address instead of the hostname. I've edited my answer to include some troubleshooting options - keep me posted. – Seamus Jul 31 '22 at 08:05
  • Today the behavior has reverted to what I described in the original question: "File exists" if the mount point exists, and "No such file or directory" if it doesn't. No error if I run the same command as root, but then the mount is root-owned and I have no access from my unprivileged user. It doesn't matter if I use the IP address or the hostname, and it also doesn't matter if I include the password in the URL or allow mount_smbfs to prompt for it. – Throw Away Account Aug 04 '22 at 21:03
  • @ThrowAwayAccount: Are you saying it worked for a time, and then quit working? – Seamus Aug 04 '22 at 22:31
  • No. It failed in one way, then started failing in another way. – Throw Away Account Aug 12 '22 at 22:51
  • I was issued a new Mac by my employer, with mount_smbfs 5.0.0 installed. I'm getting exactly the same behavior. But I've also enabled SMBFS on a real Windows machine. mount_smbfs works fine when mounting the Windows share. It only fails when connecting to Samba. – Throw Away Account Nov 25 '22 at 11:11
  • @ThrowAwayAccount: As the politicians say, "I feel your pain". This is a perennially frustrating experience, IMHO the result of two organizations with the poorest documentation in the industry: Apple and Synology! Since posting this answer I have found what seems to be a more consistent method of mounting my SMB drives - using Apple's automount feature. One potentially important caveat: I use Catalina & Mojave. As is de rigueur for Apple documentation is either non-existent or impossible to find. – Seamus Nov 26 '22 at 06:45
  • @ThrowAwayAccount: Here are 2 references that may help: 1, 2. NOTE #2 uses NFS mounts instead of SMB. – Seamus Nov 26 '22 at 06:48
0

The mount-point needs to be a directory on the local machine. Depending on what you are doing I like to use a folder in the local user directory.

cd ~/Desktop
mkdir user1mp
mkdir user2mp
mount -t smbfs -o nobrowse smb://user1:pass1@host/user1 user1mp
mount -t smbfs -o nobrowse smb://user2:pass2@host/user2 user2mp
-1

There appear to be 2 paths, neither ideally what you desire. Information heavily borrowed from this post:

  1. Use the command

    $ open 'smb://user@hostname/shared_drive/directory'
    

    This will use Finder to do the same thing as using the Finder menu Go->Connect to Server. This will preserve correct permissions and ownership of the share nodes.

  2. Create a mount directory, set ownership to yourself, mount the share:

    $ sudo mkdir -p /Volumes/Local_mount_folder
    $ sudo chown your_local_user /Volumes/Local_mount_folder
    $ mount -t smbfs //WORKGROUP\;user@hostname/shared_drive/directory /Volumes/Local_mount_folder
    

    Note that the last line does NOT contain 'sudo'. It is not required for the mount command in Mac OS 12.1 if you own the mount point. You will be prompted for your WORKGROUP\user domain password. WORKGROUP will be required if connecting to a domain.

    Also note that the this option will cause all nodes (files & directories) in the root (and possibly more) of the mounted share to be listed as being owned by you. That does not play well in the SMB ecosystem, IMO.

If you get an error message that 'File exists', you most likely have a mount directory by that name, owned by root, and only visible to root. You must 'sudo ls -alF /Volumes' to see it. Once confirmed you can 'sudo rmdir <folder_path>' to stop the error message.

To unmount and delete the mount point, simply:

    $ sudo umount /Volumes/Local_mount_folder

You will get an error message if you do this with any files/directories open in that share, including Terminal windows.

Thus I continue to search for a refinement on option 2 above.

  • Option 1 has severe limitations (you can't connect to the SMB server as two different users), and Option 2 doesn't work (I get the File exists error I originally encountered). The mount command only succeeds with sudo. – Throw Away Account Jan 08 '22 at 07:41
  • It probably isn't relevant, but there is no workgroup on my network, so I leave it out. The server is Samba on Linux. – Throw Away Account Jan 08 '22 at 07:43
  • You cannot mount to a mount point owned by root unless you mount it as root. However with MacOS 12.1, you certainly CAN mount to a mount point owned by you without sudo. – skitheo Jan 10 '22 at 05:06
  • Did you miss the 'chown' step? How about the 'sudo rmdir mount_point' when you get the 'File Exists' error? – skitheo Jan 10 '22 at 05:08
  • Per Samba docs, the default workgroup is "WORKGROUP" and is compiled in. https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html. You may or may not need it depending on your client configuration. – skitheo Jan 10 '22 at 05:24
  • I missed no steps. My installation of MacOS, which is 10.15.7, not 12.1, behaves contrary to your description. – Throw Away Account Jul 31 '22 at 06:14