Mount SMB shares in Ubuntu

ubuntuHere is a quick guide on how to install CIFS and use it to mount SMB shares (aka Windows shares) in Ubuntu.  This is tested on Ubuntu 12.04 but should work on most recent versions as well as other Debian releases.

First off you need to open a shell and elevate yourself to root, or alternatively you can add the word sudo in front of all of these commands.

install CIFS

apt-get install cifs-utils

now that CIFS-Utils are installed we need to create a directory that we can mount the share to.  So in my case I will create a new folder in the /media folder called sharename:

mkdir /media/sharename

next we can run the following command to mount the SMB share to our new folder. :

mount.cifs //192.168.1.1/sharename/  /media/sharename/ -o user=user,pass=password

in this example:

to unmount the share we can simply type:

umount /media/sharename

This is all fine for occasional mounting and unmounting but what if we want certain shares to be mounted at boot time?  No problem.

Edit your /etc/fstab fiile (carefully) to add an entry for the share:

cp /etc/fstab /etc/fstab-bak
vi /etc/fstab

add the following to the bottom of the file:

//192.168.1.1/sharename  /media/sharename  cifs  username=username,password=password  0 0

At next system startup the drive should be mounted automatically.  additional as the entry is now in our fstab file we don’t need to remember the whole command line and can simply type the following to mount the share.

mount /media/sharename

We could also use the file_mod eand dir_mode options to set the share permissions:

//192.168.1.1/sharename  /media/sharename  cifs  rw,file_mode=0777,dir_mode=0777,username=username,password=password  0 0

This is all just scratching the surface or SMBFS and CIFS in Linux..

 

Posted on March 20, 2013 at 23:05 by simon · Permalink
In: Linux · Tagged with: , , , , , ,

One Response

Subscribe to comments via RSS

  1. Written by Simon.
    on 19 May 2013 at 0:24
    Reply · Permalink

    works a treat, cheers.

Subscribe to comments via RSS

Leave a Reply