Samba and Windows that are used on-demand should be mounted with autofs. The system will mount or remount the share automatically as needed.
- Create /etc/smbpasswd to store the credentials for the user accessing the share
domain=domain.int username=storage password=p@ssw0rd
- Set the file permissions to 600 to prevent non-root users from viewing the password
# chmod 600 /etc/smbpasswd
- Install autofs and cifs-utils
# yum install autofs cifs-utils
- Create a folder that will serve as the root for mounts
# mkdir /mnt/smb
- Add the folder and corresponding config file to the end of /etc/auto.master
/mnt/smb /etc/auto.smb.top
- Add the following to /etc/auto.smb/top
* -fstype=autofs,-Dhost=& file:/etc/auto.smb.sub
- Add the following to /etc/auto.smb.sub
* -fstype=cifs,credentials=/etc/smbpasswd,uid=99,gid=99,file_mode=0664,dir_mode=0775,nounix,iocharset=iso8859-15 ://${host}/&
- Replace the UID and GID values with the user the share will be mounted as
- file_mode is the permissions assigned to share files
- dir_mode is the permissions assigned to share folders
- Enable and start the autofs service
CentOS 7/8
# systemctl enable autofs # systemctl start autofs
CentOS 6
# chkconfig autofs on # service autofs start
- Test accessing a share. It may take a couple of tries to mount.
# ls /mnt/smb/<server>/<share>
Was this helpful?
0 / 0