Mounting Samba Shares on Ubuntu

Windows and Linux logos

As some mooey5775 readers may know, I own a (pretty bad) hard drive that I keep permanently attached to my network. I would call it a NAS, but it probably doesn’t even deserve that status. However, the important part is that it works, and doesn’t experience that much load, making it a perfect candidate to mount on my server and give it the extra storage space that it potentially needs.

Windows and Linux logos
Sharing is caring

I can already think of a few possible ways to use this, including backups for my site, large downloads, and storing stuff you don’t want anyone finding on your local disk.

If you remember my tutorial on mounting a Samba share on C.H.I.P. back in mooey5775, it didn’t work very well and had to use an awful workaround. Luckily, Ubuntu has Samba support baked into the kernel. It’ll be a lot easier and shorter than the C.H.I.P. tutorial. However, there are a few things to know before you start:

  • Do you actually have a Samba share on the network?
  • What’s the IP address of this Samba share?
  • Are you even allowed to be using it?

If you’re sure you know the answer to all of these questions, then go ahead with the tutorial.

Installation

Before actually mounting the disk, you’ll need to install a few tools using apt-get, which should be preinstalled on an Ubuntu system. Before any installation with apt-get, it’s always a good idea to update the package lists to ensure you’re fetching the most updated packages:

sudo apt-get update

If you’re root, you can just leave the sudo out.

Next, we’ll want to install cifs-utils, which will allow us to interact with the underlying technology that powers Samba, SMB/CIFS.

sudo apt-get install cifs-utils

If this command fails, then you’re on an older Ubuntu distro. In that case, you’ll want to install smbfs instead of cifs-utils. Just replace the name in the command.

Testing the Mount

To get started, we can use a quick and dirty mount just to make sure that it actually works. First, you’ll need to know if you can mount the share as a guest or with credentials. If you’re not sure, try mounting it with guest first.

Guest: sudo mount -t cifs //{IP_ADDRESS}/{VOLUME_NAME} /{MOUNTPOINT} -o guest

Credentials: sudo mount -t cifs //{IP_ADDRESS}/{VOLUME_NAME} /{MOUNTPOINT} -o username={USERNAME},password={PASSWORD}

Replace the applicable fields with the information that you know. Keep in mind that {IP_ADDRESS} is the IP address of the Samba share itself, not your computer. If you’re not sure what to use for a mountpoint, you can just make a new directory somewhere and mount it to there.

If the mount worked, don’t try to write anything to it yet. This was a quick and dirty mount, and we should not be able to write anything to it. Now, it’s time to actually automatically mount the network share.

Actually Mounting

To mount the Samba share permanently, you’ll have to modify a file located at /etc/fstab. Basically, this is the filesystem table, and it controls the mounting of drives during boot. You can also manually mount the drives that are included in the fstab file.

To begin mounting, we’ll need to open the /etc/fstab file in your favorite text editor. Just make sure that you’re editing with root privileges, so you can actually save it.

Now, you’ll need to remember back to the previous step and see if you’re a guest or have actual credentials. If you’re a guest, make a new line in the fstab file, and enter this line of text:

//{IP_ADDRESS}/{VOLUME_NAME} /{MOUNTPOINT} cifs guest,uid=1000,iocharset=utf8 0 0

Basically, this line of text specifies, in order:

  1. Location of Samba share
  2. Location of mountpoint
  3. Filesystem
  4. Guest status
  5. Linux user
  6. Character set

And don’t forget the two zeros at the end.

If you’re not a guest, you’ll want to enter this line of text:

//{IP_ADDRESS}/{VOLUME_NAME} /{MOUNTPOINT} cifs username={USERNAME},password={PASSWORD},iocharset=utf8,sec=ntlm 0 0

This is very similar to the guest mount, but it specifies some extra information:

  1. Location of Samba share
  2. Location of mountpoint
  3. Filesystem
  4. Username
  5. Password
  6. Character set
  7. Security

After you’ve added this line, save the file and run this command to remount all of the filesystems in fstab, including yours:

sudo mount -a

…and it should work! Congratulations and let me know in a comment if something doesn’t turn out right when you complete this guide.

Leave a Reply

Your email address will not be published.