Home > Mac administration, Mac OS X, Unix > Connecting to an SMB server from the command line in OS X

Connecting to an SMB server from the command line in OS X

I had a call yesterday, where someone was asking to SSH into a remote Mac workstation and mount a particular fileshare on that workstation. I had them do the following:


1. Log into the Mac with your account login and password.

2. Create a folder inside your home folder named sharename to match the name of the share on the server

Note: You should only need to create this folder if it doesn’t already exist.

3. Use the following command to mount the share, using the new sharename directory as the mountpoint:

mount_smbfs //username@servername.example.com/share ~/sharename

4. You should be prompted for your account password.

5. The SMB share should mount and you should be able to access it via the sharename directory.

To unmount the server share from using the command line in OS X:

1. Log into the Mac with your account login and password.

2. Make sure you’re not in the ~/sharename directory.

3. Use the following command to unmount the sharename share from ~/sharename:

umount ~/sharename


However, when mount_smbfs //username@servername.example.com/share ~/sharename was run, it didn’t connect and gave the following error:

mount_smbfs: server connection failed: No route to host

Trying mount_smbfs //username:password@servername/share ~/sharename also did not work. Same error, plus the user was understandably not happy with the idea of having his password in the clear.

After a bit more digging, I found the answer here. In 10.6, Apple had changed the mount_smbfs configuration so that it now expected the server’s workgroup or domain as part of the connection string. For anybody else that needs it, here’s how the command should be set up if the server is connected to an AD domain:

mount_smbfs //’DOMAIN;username’@servername.example.com/share ~/sharename

If you’re using a workgroup, it should be set up as:

mount_smbfs //’WORKGROUP;username’@servername.example.com/share ~/sharename

  1. Clayton
    July 11, 2013 at 5:53 pm

    Your information about correct syntax after 10.6 was gold! Thanks a lot!

  2. November 17, 2015 at 9:11 pm

    Unfortunately this doesn’t work in 10.10.x. If I create the directory in step 2, then the mount command elicits the error “File exists”. If I don’t, I get the error “No such file or directory”. It’s not happy either way.

  3. November 17, 2015 at 9:39 pm

    Addendum to above (since there’s no edit button). The “File exists” error can occur if a previous mount attempt succeeded even if you don’t think it did. Use the ‘df’ command to list all your mounts and see if that’s the cause of that error.

    Now my problem is that the volume is mounted but there are no files appearing when an ‘ls’ command is issued…

  4. November 17, 2015 at 9:44 pm

    …aaaand final edit (apologies!) No files appearing might just be because the file share is empty. Relevant: https://en.wikipedia.org/wiki/Rubber_duck_debugging

  5. EggFoot
    March 4, 2016 at 12:58 pm

    How does this work when there is a space in the username? Would I need to create a bash file?

  6. envoy510
    April 14, 2016 at 12:46 am

    For a space use %20 where the space would be.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 290 other followers

%d bloggers like this: