Access Windows Shares in Linux

Scenario / Question:

How do I permanently mount a windows share on my linux machine

Solution / Answer:

Make sure you have the needed packages installed

Use mount command with the smbfs setting

Secure your username and password for accessing the windows share

Make sure you have the smbfs and smbclient packages installed

RedHat – Fedora – Centos

# rpm -qa samba-client

If not installed then run:

# yum install samba-client

Debian – Ubuntu

# apt-get install smbfs smbclient

Use mount command with the smbfs setting

Edit fstab to make the mount permanent and have it automatically mount at system start

# vi /etc/fstab

Append the below line to the /etc/fstab file. Make sure that its all on a single line

//windowmachine/sharename — The name of the windows machine and the name of the shared folder

/mnt/directory — The directory on your linux machine where you want the share to be mounted

smbfs — Mount option to let mount know that you are mounting a Windows share

credentials — location of file that contains the username and password for accessing the Windows Share

//windowmachine/sharename  /mnt/directory smbfs credentials=/etc/.smbpasswd 0 0

Secure your username and password for accessing the windows share

Create a file to store your username and password:

# vi /etc/.smbpasswd

Add your username and password to the file:

username=windowsusername
password=windowspassword

Set the permissions of /etc/.smbpasswd so that only root can access the file:

# chmod 600 /etc/.smbpasswd

Re-read your fstab and re-mount the entries:

# mount -a
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
Fabio Milano has written 79 articles for us. Fabio Milano is a certified RHCE, MCP, and CFOI. He runs an IT consulting and services company called RDS Support inc. Website:http://www.rdssupport.com
The information provided is for educational purposes only. All content including links and comments is provided "as is" with no warranty, expressed or implied. Use is at your own risk and you are solely responsible for what you do with it.

3 Comments so far

  1. Spamboy on March 19th, 2010

    Great article! It did exactly as stated and the .smbpasswd file is a nice touch.

    One note: some modern distros will require the the use of ‘cifs’ instead of ‘smbfs’ in the /etc/fstab file. Otherwise, you might get this error:

    mount: unknown filesystem type ‘smbfs’

    Hope this helps someone else. Cheers!

  2. Senthil Kumar on May 26th, 2010

    the above comment helped me! :-) nice article.

  3. Plastix on May 14th, 2011

    i have been trying to create windows shares on ubuntu machines. i have a centos 5.5 server. i want to create shares on the server for students but i am having trouble setting it up.

    i tried the above but to no succes.

    can anyone redirect me to any simple url regarding this .. please

Leave a reply