天天看點

samba案例配置及自動挂載

 samba案例配置

1、安裝samba服務,

rpm安裝所需包:perl-Convert-ASN1(依賴包)、samba(服務程序)、samba-common(配置檔案),samba-client(smb-client用戶端)。

2、小案例配置

要求:

  a、samb使用user安全級别,建立三個共享目錄,/home/samba,/tmp/user1,/tmp/user2;

  b、/home/samba的共享名為public,smb使用者對其有可讀權限,/tmp/user1為user1的共享共享目錄,/tmp/user2為user2的共享目錄。

a、配置:

      #vim /etc/samba/smb.conf

        #======================= Global Settings =============

        workgroup = MYGROUP

        server string = Samba Server Version %v

        interfaces = 192.168.2.1/24          

        bind interfaces only =YES          #綁定server監聽的ip

        hosts allow = 127. 192.168.2.        #僅允許127.0.0.0、192.168.2.0網段通路

        log file = /var/log/samba/%m.log     

        #======================= Share Definitions ============

[public] 

        comment = Public's samba directory

        path = /home/samba

        public = yes

        writable = no

        [user1]                    #共享名

        comment = this is user1's samba directory  #描述

        path = /tmp/user1                     #實體路徑

        public = no                            

        writable = yes      #可寫

        write list = user1  #可寫使用者

        [user2]         

        comment = this is user1's samba directory

        path = /tmp/user2

        public = no

        writable = yes

        valid users = user2                      #有效使用者

b、建立使用者

#useradd user1

#echo "123" | passwd --stdin user1

#useradd user2

#echo "123" | passwd --stdin user2

c、建立目錄,并修改所有者

chown user1.user1 /tmp/user1

chown user2.user2 /tmp/user2

echo "test1" > /tmp/user1/user1.txt

echo "test2" > /tmp/user2/user2.txt

測試,

 user1不可通路user2的目錄,

<a href="http://blog.51cto.com/attachment/201301/202729564.jpg" target="_blank"></a>

user2可以通路user1的目錄,但僅有讀取權限,和執行權限

<a href="http://blog.51cto.com/attachment/201301/202832724.jpg" target="_blank"></a>

3、挂載samba共享的各種方式:

手動挂載:

[root@client tmp]# mkdir abc

[root@client tmp]# mount -t cifs //192.168.2.1/public  /tmp/abc -o username=user1

[root@client abc]# cd /tmp/abc/

[root@client abc]# ll

總計 0

drwxr-xr-x 2 root root 0 12-19 17:20 public

-rw-r--r-- 1 root root 0 12-19 17:20 public.txt

<a href="http://blog.51cto.com/attachment/201301/202850419.jpg" target="_blank"></a>

mount (rw,)但是并不能建立修改目錄或檔案,僅有可讀權限,

smb伺服器端,public共享的權限值為僅可讀。

不了解,為什麼挂載時還是顯示rw呢,

2、開機自動挂載

#vim  /etc/fstab

//192.168.2.1/public    /tmp/abc                cifs    defaults,username=user1 0 0

[root@client tmp]# mount -a

Password: 

或//192.168.2.1/public    /tmp/abc       cifs    defaults,username=user1,password=123 0 0     

<a href="http://blog.51cto.com/attachment/201301/202924474.jpg" target="_blank"></a>

3、為保證使用者賬号及密碼安全,将賬号與密碼存放在可讀的檔案中

//192.168.2.1/public    /tmp/abc      cifs    defaults,credentials=/etc/samba/pwd.txt 0 0

#vim  /etc/samba/pwd.txt  (以username,password為關鍵字進行讀取,可以寫多個使用者,第一個使用者可以,就直接挂載了)

username=user1

password=123

#chmod 400  /etc/samba/pwd.txt

4、為節約帶寬,設定逾時後,自動解除安裝

#vim  /etc/auto.master

/home  /etc/smb.misc   --timeout=05

#vim  /etc/smb.misc

smb     -fstype=cifs,credentials=/etc/samba/pwd.txt  ://192.168.2.1/public

:wq

#vim  /etc/samba/pwd.txt    

# service autofs  start

<a href="http://blog.51cto.com/attachment/201301/202942733.jpg" target="_blank"></a>

4、通路windows共享

1、建立共享檔案smb 

<a href="http://blog.51cto.com/attachment/201301/203006633.png" target="_blank"></a>

2、開機guest賬戶

<a href="http://blog.51cto.com/attachment/201301/203031147.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201301/203042501.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201301/203053870.png" target="_blank"></a>

本文轉自 劉園  51CTO部落格,原文連結:http://blog.51cto.com/colynn/1109927

繼續閱讀