2011年10月21日 星期五

auto mount windows shares on linux filesystem


如何讓unix可以自動掛載windows分享資料夾:

實例: Linux CentOS 5.4 + Windwos XP
目的: 要將Windows主機smbhost所分享出來的share資料夾,
其存取帳號為user,密碼為pass,
以唯讀,uid=xxx,gid=yyy身份
掛載在Linux主機的/mnt/smbhost/share目錄上供存取
方法:
1.root建立linux掛載點
#mkdir /mnt/smbhost

2.root修改linux自動掛載相關組態檔,credentials帳密另存其他位置
#vi /etc/auto.master
/mnt/smbhost /etc/auto.smbhost
#vi /etc/auto.smbhost
share -fstype=cifs,ro,noperm,credentials=/root/smbhost.autofs,uid=xxx,
gid=yyy ://smbhost/share
#vi /root/smbhost.autofs
username=user
password=pass

3.root保護linux自動掛載相關組態檔
#chmod 600 /etc/auto.smbhost /root/smbhost.autofs

4.重新啟動自動掛載服務autofs
#/sbin/service autofs restart

5.一般用戶利用cd進到自動掛載目錄取用資源
> cd /mnt/smbhost/share

6.採用自動掛載前可先用如下samba客戶端指令測試遠方資料夾的帳密及內容正確與否:
> smbclient -L smbhost -U user # 以帳密user/pass,列出smbhost主機有何分享資料夾
Password:

> smbclient '//smbhost/share' -U user # 以帳密user/pass,連上分享資料夾//smbhost/share
Password:
Domain=[SATURN] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
smb: \> help # 列舉可用指令
smb: \> ls # 列舉目錄內容
smb: \> cd folder # 切換到foler資料夾
smb: \foler\> ls

參考:
http://wiki.centos.org/zh-tw/TipsAndTricks/WindowsShares
http://linux.vbird.org/linux_server/0370samba.php

沒有留言: