Google Plus

How to Mount a SMB/CIFS Share as an Automount on CentOS/Fedora/RHEL

Written by Mel Kham on . Posted in Linux tutorials

In This  tutorial  we  will show  you  How  to automatically mount/unmount a SMB/CIFS Windows share on a CentOS/Fedora/RHEL server.linux-logo



You need to open terminal and follow the instructions bellow:

1-Install the  Automounter

#  yum install autofs

 
2-Install samba (client)


#yum install samba-client samba-common

3-Next you have to add an entry to the file /etc/auto.master, like so:

 

# file: /etc/auto.master
# ...
# ...
/mnt/cifs_share    /etc/auto.cifs    --timeout=600 --ghost

4-Now we’ll need to create the mount point:

 

% mkdir /mnt/cifs_share

5-now create the file /etc/auto.cifs:

 

share_data    -fstype=cifs,rw,noperm,credentials=/etc/credentials.txt    ://192.168.1.x/windows_data

6-And finally, create the credentials.txt file.

# /etc/credentials.txt
username=user_windows
password=pass_windows

7-The last step is to startup the automounter service (/etc/init.d/autofs).


% /etc/init.d/autofs start

 

8-Once done you should now be able to cd to /mnt/cifs_share/windwos_data.
    

% cd /mnt/cifs_share/windows_data
 
% pwd
/mnt/cifs_share/windows_data

9-You can confirm that the mount is being accessed correctly by checking the active mounts:
    

% mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
//192.168.1.x/windows_data on /mnt/cifs_share/windows_data type cifs (rw,mand)

 

 And is done

For questions please refer to our Q/A forum at : http://ask.unixmen.com

Mel Kham

Founder of Unixmen, Living in Amsterdam. Am working in my free time to help people to understand the Opensource and to explain them in easy way how to make the fist steps to the the light. Working day and night with my Co-founder Zinovsky to keep this website live even with less resources.
  • Eric

    If you use /etc/fstab then autofs isn’t needed

    add to /etc/fstab the samba mount
    //192.168.1.x/media_hdd/ /home/username/mediaplayer/ cifs credentials=/home/username/credentials,exec 0 0

    enter username= and password= into /home/username/credentials if needed. If the share doesn’t require a user or pass then you may at least need password= with nothing else.

    mount -a

    and it will be mounted. If you reboot the mount point will be mounted from /etc/fstab.

    • http://enteryoursiteURL... pirat9

      Hi Erix, Thx or the update; i will update the post today later

  • http://www.happyassassin.net Adam Williamson

    On F15+ you can just do this:

    //Path/To/Share /mnt/point cifs user=guest,noauto,comment=systemd.automount 0 0

    in /etc/fstab. systemd will handle the mounting for you.

    Eric’s suggestion is also correct, but this method will cause the share to be mounted on first access, not at boot time: if you do it Eric’s way, the system might wait for the network to be up in order to mount the share during boot, and if you use Wi-Fi or something, that can slow down boot.

  • Seighalani

    hi thanks
    but section 3  confused me

    Next you have to add an entry to the file /etc/auto.master, like so:
     

    # file: /etc/auto.master# …# …/mnt/cifs_share    /etc/auto.cifs    –timeout=600 –ghostplease guide me with an example. thanks in advance

Like us on Facebook

This week Top Posts

Write for us

Recent Comments

Dominik Bauer

|

thx a lot!

Maximiliano Osorio

|

Osom. Thank you.

Sam

|

Thanks much. It worked like a charm.

HailsandNails

|

Actually, what I see too much of, and what Microsoft actually (sorta) did with Windows 8 is think forward. And let’s be brutally honest. Windows 8 is actually NOT as bad as people is making it out, they’re just freakishly afraid of change (which Linux users are as well, it seems)

SK

|

Yes i will. Keep visiting. Subscribe us to get daily updates. Thanks for the comment

 
IDG Tech Network
Copyright © 2008-2013 Unixmen.com .
Maintained by Anblik .