Search The Site

How To Permanently Mount A Windows Share On A Linux Box

Mounting Windows Shares In Linux

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

First we need to make sure you have the smbfs and smbclient packages installed on your linux box.

If you are using RedHat, Fedora & Centos enter the following in a terminal window with root priviledges.

# rpm -qa samba-client

If the packages are not installed then run:

# yum install samba-client

If you are using Debian & Ubuntu then enter the following:

# apt-get install smbfs smbclient

Next, we need to edit fstab to make the mount permanent and have it automatically mount at system start

# vi /etc/fstab

Next we are going to add the following info to the /etc/fstab file. Make sure that it is all on a single line.

  • //windowsboxname/sharename — The name of the windows box and the name of the shared folder on the windows box
  • /mnt/directory — The directory on your linux box 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 box shared folder

Your fstab file should now look like the following:

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

Next we need to secure your username and password for accessing the shared folder on the Windows box

Create a file to store your username and password:

# vi /etc/.smbpasswd

Next, add your username and password to the file:

username=windowsusername 
password=windowspassword

Next, we need to 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

That is it, you are finished, you should now be able to access a shared folder on a Windows box. :)