Mounting SMB shares in Ubuntu

Posted on Jun 23, 2014

If you've spent any amount of time running a Linux machine on a Windows network, you've probably had the need to share files between the two. This seems like it should be a trivial matter, but as often as not, it seems to produce bouts of sheer insanity. The problem usually lies in the realization that Windows uses SMB and that Linux tends toward transit over SSH (rsync, scp, sftp.)

As denial sets in, you might be tempted to try to use a less-than-elegant solution to convince yourself that direct file transfer isn't really all that big of a deal. If we were to follow this madness, we'd see something along these lines.

if size < 20M
  "GMail"
elsif size < 5G
  "DropBox"
elsif size < 16G
  "Thumbdrive"
else
  throw "Bah. If Windows just included rsync... *Something about RMS*... *Incoherent Mumbling*"

That's all well and good, but what if we're talking SUPER large files? Say, a virtual machine with a large dataset on it? At this point, the obvious solution is to move into a small log cabin, continuing life as a hermit, cut off from the rest of the world.

Hi Dexter. You look a bit hairier now.

Or, we could take a different approach. Rather than complaining that Windows doesn't include a rsync server like we'd see in our happy Unix world, maybe we should just accept that in Windows land, we use NFS.

Okay. Teeth clenched, eyes-wide-shut, eyebrows furled. Ready? Well, it's actually going to be rather painless. Three steps, as a matter of fact.

To start, we'll install cifs-utils. This will give our system the capability to mount an NFS share. That was the difficult step. Done.

sudo apt-get install cifs-utils

Next we need to create a file that contains the credentials that we'll use to mount the share. The password is in plain text, so I'd recommend using the credentials for a limited account, if possible. Create this file in your home directory, and fill in the appropriate values.

username=jdoe
password=MY_SECURE_PASSWORD
domain=EXAMPLE.COM

Lastly, we'll mount the remote server as a cifs share, using the credentials we saved in /home/jdoe/credentials.

sudo mount -t cifs //fileserver.example.com/images /mnt/example.com/ -ocredentials=/home/jdoe/credentials

At this point you should be able to treat /mnt/example.com just like you would if you were connected to it from a Windows host. No pain. No reason for madness. Now let the file transfers begin!