天天看點

samba共享

samba共享目錄

安裝samba服務

yum -y install samba samba-client

主配置檔案

/etc/samba/smb.conf

案例一、windows與Linux之間共享

背景:共享目錄,任何人都可以通路,不需要輸入密碼,隻讀

vim etc/samba/smb.conf

找到

  workgroup = MYGROUP

  修改為

   workgroup = WORKGROUP

security = user

修改為

security = share

在最後添加:

[jqm]

    comment = share all

    path = /tmp/sambadir

    browseable = yes

    public = yes

    writable = no

啟動服務

/etc/init.d/smb start

建立目錄存放目錄

mkdir /tmp/sambadir

建立測試檔案

cp /etc/passwd /tmp/sambadir/1.txt

mkdir /tmp/sambadir/test

賦予權限

chmod 777 /tmp/sambadir/test

ll /tmp/sambadir/

總用量 8

-rw-r--r-- 1 root root 1760 8月  23 15:15 1.txt

drwxrwxrwx 2 root root 4096 8月  23 15:16 test

測試一、

在win7中測試:

按win鍵+R鍵,在對話框中輸入\\192.168.10.106,會出現設定共享的名字jqm

打開後會發現兩個檔案test和1.txt,發現在test目錄下不能建立添加,在1.txt檔案中也不能修改

測試二、在Linux下測試

1.安裝samba-client

smbclient //192.168.10.106/jqm

Enter root's password:

Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23-35.el6_8]

Server not using user level security and no password supplied.

smb: \> ls

.                                   D        0  Tue Aug 23 15:16:07 2016

..                                  D        0  Tue Aug 23 15:15:29 2016

test                                D        0  Tue Aug 23 15:16:07 2016

1.txt                                     1760  Tue Aug 23 15:15:56 2016

注意這裡要求輸入密碼部分直接回車即可

可以看到共享的檔案,但是也不能再裡面做任何操作

2.使用挂載方式:

安裝挂載時需要的包

yum -y install cifs-utils

mount -t cifs //192.168.10.106/jqm /opt/

Password:

要求輸入密碼同樣直接回車即可

進入opt目錄下檢視

[root@jqm opt]# ls

1.txt  test

可以發現共享的檔案出現,但是同樣不能進行任何操作

#############################################################

案例二、

背景:共享目錄,任何人使用使用者名及密碼通路,可讀寫

進入配置檔案

在最後添加

[lc]

        comment = share for users

        path = /tmp/sambadir

        browseable = yes

        writable = yes

        public = no

建立測試賬戶

useradd smbuser1

建立samba賬戶

pdbedit -a smbuser1

重新開機服務

/etc/init.d/smb restart

測試一、在Linux中測試

使用使用者名及密碼直接登入測試

smbclient -Usmbuser1 //192.168.10.106/lc

輸入smbuser1的密碼進入

可以在共享的test和1.txt中進行修改、添加等操作

測試二、win7中測試

按win鍵+R鍵,在對話框中輸入\\192.168.10.106,需要輸入使用者名及密碼才能進入進行操作

測試三、Linux中使用挂載方式

mount -t cifs -o username=smbuser1,password=123123 //192.168.10.106/lc /opt/

挂載完成後可以進入共享檔案中進行操作

注意:

1.建立samba使用者:

pdbedit -a 使用者名

2.删除samba使用者

pdbedit -x 使用者名

3.列出samba使用者清單

pdbedit -L

4.列出samba使用者清單詳細資訊

pdbedit -Lv 

上一篇: nfs共享
下一篇: 共享池