How to Mount Windows Share to Linux Machine using CIFS

Introduction :-

This is the blog, How to mount Windows Share to Linux machine permanently using CIFS. 

For an Administrator, it is required many times to mount Windows share into Linux Server, It could be due to some backup or copy data from Linux machine to Windows machine.

Requirement :-

We need two working PC :
1- Windows PC where share needs to create.

2- Linux PC where share needs to Mount.

Configuration Steps :- 

1- Windows Machine side configuration :- 

1 A- Create a shared folder and assign permission to a user using below steps :

- Create a folder name website in any drive 
-  go to properties 
Select Share TAB 
Click on Advanced Sharing button 
- Select the Check box Share this folder 
- Select permission button 
- Click On ADD 
- Enter User Name whom you want to give permission -
- Select Full Control check box 
- click on Apply and OK

Note- The Same User Name and it's password, We will use to Mound this folder into Linux machine.


2- Linux Machine side configuration :-

We need to install the following package 

1- CIFS-UTILS
2- samba-client samba-common

2 A- Install cifs-utils using command yum install.


[root@testsvn ~]# yum install cifs-utils

Check install package using command rpm -qa

[root@testsvn ~]# rpm -qa | grep cifs
cifs-utils-4.8.1-20.el6.x86_64
[root@testsvn ~]#


In above query cifs 4.8 package get installed.

2 B - Install samba-cifs and samba-common package using yum command

[root@testsvn ~]# yum install samba-client samba-common

Check install package using command rpm -qa

[root@testsvn ~]# rpm -qa | grep samba
samba-client-3.6.23-35.el6_8.x86_64
samba-common-3.6.23-35.el6_8.x86_64
samba-winbind-3.6.23-35.el6_8.x86_64
samba-winbind-clients-3.6.23-35.el6_8.x86_64

[root@testsvn ~]#


In above query samba-client, samba-common, samba-winbind and samba-winbind-clients package would be available.

2 C - Now create credentials file, and add user, password detail

[root@testsvn ~]# vi .smbcredentials

username=User_Name                    This user would be same whom we give permission on shared folder.
password=User_Password

Save and Exit  from file.

Note-  if you are sharing folder on a PC member of Domain controller then use this format for the user - Domain_Name\User_name.

2 D- Now change credentials file permission -

[root@testsvn ~]# chown root .smbcredentials                  To make root owner of this file
[root@testsvn ~]#
chmod 600 .smbcredentials To Give root user RW permisson



2 E- Create mount directory and FSTAB entry to add this mount permanently -

Create a mount directory - 
[root@testsvn ~]# mkdir /mnt/winshare

Let's test access on share folder using mount command
[root@testsvn ~]# mount -t cifs -o credentials=/root/.smbcredentials //10.0.1.13/websites /mnt/winshare

In above example detail as follow:

mount                                       =   command
-t cifs                                         =  where t is type and Cifs is filesystem
-o                                                =  where -o is option
credentials                              =  command to define credentials path
/root/.smbcredentials        =  This path contain User_Name and Password
//10.0.1.13/websites           =   Windows Share path
/mnt/winshare                     =  Linux PC mounting directory

Let's check mounting using mount command -

[root@testsvn ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
//10.0.1.13/websites on /mnt/winshare type cifs (rw)
[root@testsvn ~]#


Windows Share folder have been mounted successfully !!!!

Let's Make FSTAB entry to mount permanently 

[root@testsvn ~]# vi /etc/fstab
 Append below line into this file.
//10.0.1.13/websites /mnt/winshare cifs  credentials=/root/.smbcredentials,uid=1000,gid=1000
Save and Exit from file. 
Now you fstab file looks like below :
/etc/fstab
# Created by anaconda on Tue Feb 2 12:30:07 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1
UUID=3291b0ee-d2d5-44eb-9418-d2b81c72ea8e /boot ext4 defaults 1 2
/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
//10.0.1.13/websites /mnt/winshare cifs credentials=/root/.smbcredentials,uid=1000,gid=1000

Run command mount -a to refresh entry.
[root@testsvn ~]# mount -a
3 - Let's check mounted folder-
Go to mount directory
[root@testsvn ~]# cd /mnt/winshare/
Create test dir using mkdir command
[root@testsvn winshare]# mkdir test
Now go to Windows PC and check test folder would be there.













We have successfully mounted Windows share folder to Linux machine.




That's All
!!!Cheers!!!