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?

3
  • Are you still looking for an answer here - or have you moved on?
    – Seamus
    Jul 3 at 19:28
  • Having an answer would be better than not having it. Jul 31 at 6:08
  • Well there you are :) Hope it helps.
    – Seamus
    Jul 31 at 6:31

3 Answers 3

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
0

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.

5
  • 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. Jul 31 at 6: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. Jul 31 at 6: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 at 8: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. Aug 4 at 21:03
  • @ThrowAwayAccount: Are you saying it worked for a time, and then quit working?
    – Seamus
    Aug 4 at 22:31
-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.

6
  • 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 .