Wednesday, November 11, 2009

How I finally got my Samba share mounted under Crunchbang

I've been running Crunchbang 9.04 for a little less than a week and although almost everything has worked like a charm so far, I had a heck of a time getting my Samba share to mount. Crunchbang does not come with Nautilus installed; it comes with PCManFM, which is very fast and I love using it normally, but it is totally unable to mount Samba shares like Nautilus can.

There are a wide vareity of tools available under Linux that will connect to a Samba share, most of which don't actually mount the share, instead connecting over the smb protocol (you have probabably seen "smb://" in the address bar of Nautilus or Konquerer at some point; that's why). I could have tried something like that but actually mounting the drive seemed like the way to go on Crunchbang, since that way any file manager would be able to browse it, and the Samba mounting utilities have been part of Linux forever, so they should work pretty well under any distro, right? I've used "mount -t smbfs", "mount -t cifs", "mount.smb", "mount.cifs" in other distros with no problems, but for some reason on Crunchbang each time I got various error messages that I didn't record.

I spent several days Googling and trying out various alternative options like fusesmb, smbnetfs, and gigolo. Fusesmb and smbnetfs are supposed to be userspace apps where you give it a directory and it sets up all of the shares on your local network inside that directory. It seemed great; I didn't even need root permissions! Filled with hope, I ran "smbnetfs ~/network" and then browsed into the "network" folder, only to find my wife's Windows laptop listed but not the Samba share I'm trying to get to. It was insanely frustrating and I almost gave up and went back to Ubuntu.

To make a long story short, I eventually got it working in 3 steps:
  1. I installed smbfs, which is not included in Crunchbang by default, by running "sudo apt-get install smbfs"
  2. I created a new directory to mount my samba share by running "mkdir ~/smbshare"
  3. I mounted the share inside the new directory by running "sudo mount.cifs //ServerIPAddress/jizldrangs ~/smbshare -o username=jizldrangs, password=mypassword".
Concerning Step #3, you may be thinking what I thought: "I don't want to type in my password into the line because it will be displayed on the screen; I'll just run the base command without the options and wait for it to prompt me for a password." Hold on there, hotshot, you are about to subject yourself to the same several hours of frustration that I subjected myself to. You have to put the username and password into the command the way I specified above; I read somewhere that there is a bug with the mount command when used with smbfs such that it won't work unless you actually type you username and password into the command. Major bummer, huh?

I only needed to do this once, so it worked out just fine for me, but if you have to do this a lot, or want to script it and don't feel comfortable storing your password in a script, you can also do the following:
  1. Create a new text file containing the username and password in the format specified above except on separate lines (i.e. put "username=yourUserName" on the first line and "password=yourPassword" on the second line).
  2. Save it somewhere out-of-the-way.
  3. Change the owner to root by running, "sudo chown root /path-to-file/file-name"
  4. Remove all permissions except read and write by the owner (which we just set to root) by running "sudo chmod 600 /path-to-file/file-name". This will ensure that only the root user can read the file containing your credentials.
  5. Modify the mount command above to, "sudo mount.cifs //ServerIPAddresss/share-name /path-to-mount-directory/mount-directory-name -o credentials=/path-to-file/file-name"
HTH!

2 comments:

  1. Awesome! I've been searching for this answer for quite a while. Thanks.

    I feel kind of stupid for asking this, but you wouldn't happen to know what the command to dismount the share would be, do you?

    ReplyDelete
  2. No prob. It's "sudo umount /path/to/mount/location". In my example above it would be "sudo umount ~/smbshare"

    ReplyDelete