第一步當(dāng)然是安裝各種需要的軟件包
sudo yum install samba-client samba-common autofs
完成后你應(yīng)該會在/etc下發(fā)現(xiàn)
auto.cifs auto.master或者auto.smb
第二步配置auto.master文件
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
# "nosuid" and "nodev" options unless the "suid" and "dev"
# options are explicitly given.
#
/net -hosts
#
# Include /etc/auto.master.d/*.autofs
# The included files must conform to the format of this file.
#
+dir:/etc/auto.master.d
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
#############################################################
/mnt/share_data /etc/auto.cifs --timeout=600 --ghost
注意添加最后一行;
/mnt/share_data代表掛載的本地路徑,/etc/auto.cifs以cifs形式自動掛載windows共享(一般而言windows共享使用的是cifs協(xié)議),該文件如果不存在則第四步中創(chuàng)建。
第三步創(chuàng)建文件夾
sudo mkdir /mnt/share_data #即第二步中設(shè)置的本地路徑
第四步創(chuàng)建并修改/etc/auto.cifs
# 添加一行
folder_name -fstype=cifs,rw,noperm,credentials=/etc/my_cred.txt ://*.*.*.*/share
folder_name即在本地的/mnt/share_data目錄下的文件夾名稱,未來該目錄則為掛載的具體目錄
credentials=/etc/my_cred.txt一般windows共享需要用戶名密碼,為了方便我們不講用戶名密碼直接寫入文件,而是另存到其他文件由auto.cifs調(diào)用
://*.*.*.*/share為windows的共享地址及目錄
第五步配置用戶名密碼文件
sudo vim /etc/my_cred.txt
# add those lines
-----------
# /etc/my_cred.txt
username=your_username
password=your_password
第六步重啟查看是否掛載成功
sudo service autofs restart
完成上述步驟,進入/mnt/share_data,我們會發(fā)現(xiàn)一個folder_name的文件夾,進入并查看是否掛載成功
cd /mnt/share_data
ls
cd folder_name
ls