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

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

How to Mount a SMB/CIFS Share as an Automount on CentOS/Fedora/RHEL or Using the fstab file approach

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

Secure credentials.txt as root with chmod 600 credentials.txt

 

ALTERNATIVE INSTRUCTIONS

Redhat CIFS mounting with FSTAB and credentials file

As the root user:

Create files in /etc/smbmounts for each set of credentials you need to mount various windows fileserver shares

i.e. server1,server2, and server3 or domain1,domain2, and domain3

or hide these files by naming .server1 …..

Example file serverX should contain the following with no whitespaces

username=windowsusername

password=windowspassword

domain=windowsdomain

chmod 600 on the serverX or domainX or whatever name you chose for them

Edit /etc/fstab and add the following to the end:

# For a password protected rw share

//servername/sharename /mount/sharename cifs credentials=/etc/smbmounts/.server1,iocharset=utf8,file_mode=0777,dir_mode=0777 1 3

# For a read only share

//servername/sharename /media/sharename cifs guest,iocharset=utf8 1 3

Comments are closed.