Mounting a Samba Share that has Spaces

Last updated: Sep 18, 2007

It is often required to mount a shared Windows drive instead of browsing the share through nautilus or smbclient. For example you may want to set up a backup script that copies a local linux directory and uploads it to a windows share each night. This can be easily accomplished with a simple bash script; however, the script needs to be able to browse to the share through a normal directory. Since the bash script can only interact with regular directories we have to simulate a directory by mounting the share as a pretend linux filesystem (smbfs). This is what we are going to do today.

Things you need

  • Samba

  • smbfs

  • a text editor

Installing Samba

Ubuntu/Debian - sudo apt-get install samba Gentoo - emerge samba

Installing smbfs

Ubuntu/Debian - sudo apt-get install smbfs Gentoo - emerge smbfs

Making the Directory

As root: mkdir /mnt/windowsShare

Automatically mount the share on boot

nano -w /etc/fstab Add the following line near the bottom

//192.168.x.x/My\040Share /mnt/windowsShare smbfs username=user,password=pass 0 0

Replace 192.168.x.x with the host’s ip address (Find Your IP Address) Replace My\040Share with the share name (the ‘\040’ is the linux way of making a space.) Replace user with your actual username and pass with your password.

Now the next time you boot your computer you will automatically have a directory ‘/mnt/windowsShare’ that will contain the files/folders from the host computer. You can interact with this directory just as you would with any other directory.

To force the change now with having to reboot type this command:

sudo mount -a

This command will simulate a reboot by remounting everything in fstab that isn’t mounted.

Need to print shipping labels on your site?

Checkout my product RocketShipIt for simple easy-to-use developer tools for UPS™ FedEx™ USPS™ and more.

Get notified on new posts or other things I'm working on