Adding Windows Shares in Linux

I was recently asked to access Windows Share from within Linux. It’s not an unusual task, but it’s not common either. Windows shares are a bit confusing to Linux users because Microsoft use backslashes which are designated as an escape key in Linux. Windows shares typically use this \\Windows\Directory\Structure.

The easiest way to access a Window share is to mount it from within Linux. In this example, we have a Windows share called \\Windows\Directory\Structure. We want to mount it in Linux, so that it is available on /mnt/share. The following are the steps to take to mount Windows shares on a Linux box. I’m using Ubuntu 11.04 on this example.

Create A Directory

First, we need to create a destination mount. In this case, /mnt/share.

sudo mkdir /mnt/share

Mount The Share

Next, we will mount the Windows share using CIFS or Common Internet File System. CIFS is similar to the SMB protocol. You can use SMB as well, but CIFS worked for me.

sudo mount -t cifs //Windows/Directory/Structure
  -o username=your_username,password=your_password /mnt/share

Add To Fstab

To have a more permanent structure, we will add the Windows share to /etc/stab, so that every time Linux is rebooted, the shared drive will be mounted automatically. Jus edit the /etc/fstab file and add the following:

//Mounted/Directory/Structure /mnt/share cifs
  u<var id="yiv1712973071yui-ie-cursor"></var>sername=your_username,password=your_password, 0 0

Once the changes are made, you can mount all using this command

mount -a

Finally, you can then check if the Windows share drive is available from within /mnt/share.

Mount Bind

The mount command in Linux is used to attach a file system to a certain device. One of the least used features within mount is called bind. With bind, you can mount a certain directory to another directory within the file system. The result is, the files are accessible from both directories. This feature is particularly helpful when sharing files. I use it to map the home directory of a FTP user to the home directory of the web server. In this particular example, I’m using a FTP user called ‘ftpuser’ and mapping the drive to ‘/var/www,’ which is Apache’s home directory.

Mount Bind Command

mount --bind /var/www /home/ftpuser

Make It Permanent

To make this mount permanent, you need to add it to /etc/fstab.

/var/www /home/ftpuser bind defaults,bind 0 0