Mounting a Windows (SMB) Share from the OS X Command Line

There may be times when you would prefer to mount a Windows (smb) share from a Terminal in OS X; I certainly prefer to use the command line, and use it as much as possible – I just find it quicker than using Finder.

Mounting a share is pretty simple, using the mount command:

mount -t smbfs //servername/sharename mount/path

So, for example, if you have a server/PC called “WindowsPC” with a sharename on there of “Shared”, and you wanted to mount it at path /Users/daz/mnt, the command would be:

mount -t smbfs //WindowsPC/Shared /Users/daz/mnt

You may be prompted to supply a password for the share, but then it will mount.

Also note that if you don’t have DNS/Name resolution in place, servername can also be an IP address.

This will take your local OS X username, and use it to authenticate.  If you want to use a different username to authenticate as, you would put it before the machine name or IP like so:

mount -t smbfs //username@servername/sharename /mount/path

There are a few other options you may require, for some setups.  You can read the Apple manpage entry for mount_smbfs at the link below:
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man8/mount_smbfs.8.html

Of course, you aren’t just limited to mounting shares via smb on Windows machines – OS X also offers Windows File Sharing, which uses the same protocol, as does Samba in Linux/BSD. You can use the same commands here to mount shares on other systems utilising this protocol.

After you get used to using the command line, you’ll probably find it much quicker/better at certain tasks. I’ll be supplying lots of tips here on droptips, to help you get to grips with using a Terminal more.