0

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

Apparently, on older versions of MacOS you would 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.

On my MacOS 10.15.7 system, you can't run the mount command unless you're root. The error you get if you run without root depends on if the mount point exists or not.

If it does:

macbook:~ user$ mount -t smbfs //user@host/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@host/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.

If I run the command as root, then it succeeds if the mount-point exists, but the mount point is owned by root and only accessible by root.

The equivalent command on Linux accepts a -o uid=<uid> option that controls which user will own the files. The man page for mount_smbfs does not document any such option, and it doesn't accept the -o uid option.

Is there a way to do what Finder does (make the mount point owned by user) but from the command line?

2 Answers 2

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
  • I am using a directory on the local machine. It only works for root and not for normal users. Mar 4 at 14:37
-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.

5
  • 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. Jan 8 at 7: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. Jan 8 at 7: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 at 5:06
  • Did you miss the 'chown' step? How about the 'sudo rmdir mount_point' when you get the 'File Exists' error?
    – skitheo
    Jan 10 at 5:08
  • Per Samba docs, the default workgroup is "WORKGROUP" and is compiled in. 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 at 5:24

You must log in to answer this question.

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