Code Review Videos > Linux > How To Mount Mac Shared Folder On Linux

How To Mount Mac Shared Folder On Linux

Here’s the requirement: you want to work on your Linux (Ubuntu, in my case) desktop, but your data lives on an OSX / Mac machine. You need to share your folder from Mac, and connect to it from Linux.

How do you do that?

Well, there is likely more than one way to do this. But here’s a way that is working for me.

I’m going to assume you have a user account on your Mac machine that you will use when connecting. In my case this is not my regular Macbook user, but a new user I created for the purposes of a specific project. That way my own personal data doesn’t mingle with any of their stuff.

You should be able to log in with this user on your Macbook. It doesn’t need to be an admin user, but you will need an admin user (or their credentials) to do some of these setup steps.

I will be sharing out my ~/Development directory from my Mac. This is my home / user’s own directory.

Another way of writing this, which spells it out more clearly, is: /Users/{your_username}/Development.

Setting Up Your OSX Folder Share

Start by heading to System Settings…

system settings menu osx

From there, select General on the left, and then toggle the File Sharing option to on / enabled.

Then click the (i) next to the File Sharing toggle. That’s pretty unintuitive UI for OSX, but that’s what needs to be done.

enable file sharing osx

If you are logged in as your machine’s admin user, you may not see a prompt.

However, I am logged in as a none admin user, so I am required to enter some valid admin credentials:

osx sharing prompt for admin credentials

From there I can select one or more folders that I would like to share.

Click the + icon to pick a folder. You can pick a sub-folder, or a top level folder.

osx file sharing shared folders setup

I pick my user’s Development folder:

osx folder picker for file sharing

From there I need to choose which Mac users have what permissions to that folder.

I pick my own personal user and my current user to have Read & Write permissions.

You only really need to make sure you give Read & Write to whichever user you will be using when connecting to this share.

osx file sharing user permissions

Very important, and easy to miss, click the Options… button (above) and then ensure that Share files and folders using SMB is ticked, and it is On for whichever users will be connecting.

I have whited out my username as it gives away too much info for this post.

osx smb file sharing menu

Click Done, and you can close down all them menus now.

From the OSX side, we are finished.

Connecting To Your OSX Folder Share From Linux

Everything from here on in will be done via Linux command line.

Open up a new terminal and change to your home directory, if you are not already there:

cd ~Code language: Shell Session (shell)

Now you need to create a new file that will contain your remote / OSX user credentials.

I will create the file named .osxsmb-remote-user-credentials but you can call this what you like.

I use chmod 600 on that new file to ensure only my current user has any access to the credentials. This is because they will be stored in plain text. Security nightmare.

touch /home/chris/.osxsmb-remote-user-credentials
chmod 600 /home/chris/.osxsmb-remote-user-credentialsCode language: Shell Session (shell)

You may be wondering why we need to do things using plain text. I certainly was. This Stack Overflow post explains why. I have tried using sshfs for this very process, and I have found my JetBrains IDE’s do not like this approach at all.

When providing your remote connection details you will need the obvious two: username, and password.

You will also need to know your Mac’s domain.

In my case, this is Home.

You may not be on the domain of Home.

To find this out, open a new terminal and type in:

cat /etc/resolv.confCode language: Shell Session (shell)

This should spit out something like:

# lots of info about what this file is about
search Home
nameserver 192.x168.0.1
namserver fe8d:d1ce:a912:blah:blah:blahCode language: Shell Session (shell)

The line you care about is search Home. Whatever comes after search is very likely your domain.

Now open the file:

vim /home/chris/.osxsmb-remote-user-credentialsCode language: Shell Session (shell)

and add the following contents:

username=your-remote-osx-username
domain=Home
password=your-remote-osx-passwordCode language: Shell Session (shell)

Save the file.

If using vim that would be pressing esc followed by typing :wq and pressing return.

OK, that’s our credentials done.

Next, we need to create a mount point.

For this I use the /mnt directory.

cd /mntCode language: Shell Session (shell)

From here, you need to create a new directory. This directory should be empty, as I believe you can use an existing directory but the mount will ‘overwrite’ the contents until the unmount command happens.

Basically just create a new directory unless you know way more than I do, in which case why do you even need to read this tutorial?

mkdir my-osx-mounted-folderCode language: Shell Session (shell)

Now you are ready to mount the remote OSX folder on to your Linux machine.

Here’s the command I use:

sudo mount.cifs //192.168.0.26/Development /mnt/my-osx-mounted-folder -o nounix,sec=ntlmssp,noperm,rw,credentials=/home/chris/.remote-osx-credentials,uid=$(id -u),gid=$(id -g)Code language: Shell Session (shell)

I appreciate that is not the easiest thing to read. Here is a slightly more readable version:

sudo mount.cifs //192.168.0.26/Development \
  /mnt/my-osx-mounted-folder \
  -o nounix,sec=ntlmssp,noperm,rw,credentials=/home/chris/.remote-osx-credentials,uid=$(id -u),gid=$(id -g)Code language: Shell Session (shell)

This command is used to mount a network share from a remote machine to a local folder on your Linux machine. The command uses the “mount.cifs” command, which is used to mount a CIFS (Common Internet File System) share.

Here is a breakdown of the different parts of the command:

  • sudo: This is used to run the command with root privileges, which is required for mounting network shares.
  • mount.cifs: This is the command used to mount the CIFS share.
  • //192.168.0.26/Development: This is the path to the remote share that you want to mount. The IP address (192.168.0.26) is the address of the remote machine, and “Development” is the name of the shared folder on that machine.
  • /mnt/my-osx-mounted-folder: This is the local folder where you want to mount the remote share. This folder should already exist on your Linux machine.
  • -o: This is used to specify options for the mount.
  • nounix: This option disables the use of Unix extensions for the mounted file system.
  • sec=ntlmssp: This option specifies the security mode to use for the mount. In this case, it uses the “ntlmssp” security mode.
  • noperm: This option disables permission checks on the file system being mounted.
  • rw: This option mounts the file system as read-write.
  • credentials=/home/chris/.remote-osx-credentials: This option specifies the path to the credentials file that will be used to authenticate with the remote machine. The file should contain the username and password for the remote machine.
  • uid=$(id -u): This option sets the UID (user ID) of the mounted file system to the UID of the current user. This ensures that the current user has permission to access the mounted folder.
  • gid=$(id -g): This option sets the GID (group ID) of the mounted file system to the GID of the current user. This ensures that the current user’s group has permission to access the mounted folder.

If that command runs successfully, you should now be able to change directory into that new mount point and see the contents of your remote folder.

You should also have the ability / permission to create, read, update, and delete files and folders on your remote share.

If, however you see something like:

mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg)Code language: Shell Session (shell)

Then run the command it is telling you:

dmesgCode language: Shell Session (shell)

That command will spit out a lot of stuff, though it should be the very last few lines that are helpful:

[1130901.112235] CIFS: Attempting to mount \\192.168.0.26\Development
[1140902.224500] CIFS: Status code returned 0xc000006d STATUS_LOGON_FAILURE
[1150905.254507] CIFS: VFS: \\192.168.0.26 Send error in SessSetup = -13
[1160907.274521] CIFS: VFS: cifs_mount failed w/return code = -13Code language: JavaScript (javascript)

From there you can better understand what went wrong. Most likely it’s a username or password issue.

1 thought on “How To Mount Mac Shared Folder On Linux”

  1. Fantastic, it worked! A couple things though: 1) In the command you have .remote-osx-credentials, but in the earlier step you used .osxsmb-remote-user-credentials and 2) If you don’t already have it installed, then (on Ubuntu and distros using apt), you will need to do this: sudo apt-get install cifs-utils.

    Bonus item, store that command in a file and execute it (after chmod to 755 or to keep from others, chmod 700).

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.