這個服務呢,可能一些網絡管理員用得比較多,因為samba服務可以實現讓我們去在linux機器上共享一個目錄出來,然后呢讓windows機器去訪問;就像windows跟windows之間進行文件共享一樣那么方便;它也可以配置一些用戶登錄權限。
服務端
## 安裝
[root@wy ~]# yum install -y samba samba-client
解釋說明:
samba 服務端
samba-client 客戶端
## 查看配置文件
[root@wy ~]# vim /etc/samba/smb.conf
解釋說明:
[global] 全局設置
workgroup = MYGROUP 工作組
server string = Samba Server Version %v 顯示的信息(自定義的)
security = user 安全級別
user:需要經過用戶名密碼進行驗證才可以去登錄我們的samba共享的文件
shell: 假如匿名用戶,不需要用戶,不需要驗證就可以直接訪問到共享的文件,最不安全的
server:檢查賬戶以及密碼,也就是認證的 工作交由另外一臺服務器來做,是由遠程的控制臺來做的
domain:這牽扯到了windows里面的域控制器,它可以通過域控制器來進行驗證用戶的賬戶和密碼
passdb backend = tdbsam 用戶名和密碼存儲的方式,默認是tdbsam,另外兩個是smbpasswd、ldapsam
smbpasswd是使用一個工具smbpasswd去操作系統的用戶,把系統的用戶變成一個虛擬用戶映射過來,
然后我們設置一個samba的密碼。
tdbsam 與smbpasswd類似,也有不同的地方(比如密碼存儲的方式);tdbsam更安全一些
ldapsam 是基于ldap賬戶管理方式驗證用戶,需要借助于咱們的ldap服務
load printers = yes cups options = raw 這兩個是關于打印機的設置
[homes] 這個模塊是把你的用戶的家目錄是否可以共享出來
[printers] 這個模塊是打印機相關的
做個實驗,要求:共享一個目錄出來,任何人都能訪問這個目錄,不需要輸入用戶名和密碼就可以訪問,就像ftp的匿名登錄一樣,但要求是只讀,不能寫
## 編輯配置文件
[root@wy ~]# vim /etc/samba/smb.conf
security = share
workgroup = WORKGROUP //因為windows是workgroup
****在文件末尾加上
[wyy]
comment = share all //自定義的描述
path = /tmp/sambadir //共享的目錄
browseable = yes //是否允許在咱們的工作組里面
public = yes //是否是公開的
writable = no //不可寫
## 啟動服務
[root@wy ~]# /etc/init.d/smb start
啟動 SMB 服務: [確定]
## 先創建共享目錄
[root@wy ~]# mkdir /tmp/sambadir
[root@wy ~]# cp /etc/passwd /tmp/sambadir/1.txt
## 在共享目錄下創建目錄,是為了驗證是否不可寫(配置文件中配置了不可寫)
[root@wy ~]# mkdir /tmp/sambadir/test
[root@wy ~]# chmod 777 !$
chmod 777 /tmp/sambadir/test
windows下的訪問
## 打開windows的運行
## 看到在配置文件創建的那個名字
## 查看下面的目錄文件
## 來驗證不可寫
linux下的訪問
## 第一種方式登錄
[root@wy ~]# smbclient //192.168.219.129/wyy
WARNING: The security=share option is deprecated
Enter root's password:
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23-36.el6_8]
Server not using user level security and no password supplied.
smb: \> ls
. D 0 Wed Nov 16 22:06:20 2016
.. D 0 Wed Nov 16 22:05:41 2016
test D 0 Wed Nov 16 22:06:20 2016
1.txt 1383 Wed Nov 16 22:06:05 2016
35418 blocks of size 524288. 25862 blocks available
解釋說明:
不說輸入密碼,直接回車即可
## 第二種方式掛載
##先安裝關于mount相關的
[root@wy ~]# yum install -y cifs-utils
## 掛載
[root@wy ~]# mount -t cifs //192.168.219.129/wyy /opt
Password:
解釋說明:
不用輸入密碼,直接回車
## 查看掛載
[root@wy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_wy-lv_root 18G 3.8G 13G 24% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 485M 34M 426M 8% /boot
//192.168.219.129/wyy 18G 3.8G 13G 24% /opt
## 查看共享目錄
[root@wy ~]# cd /opt/
[root@wy opt]# ls
1.txt test
## 驗證在它下面的目錄是否不可寫
[root@wy opt]# cd test/
[root@wy test]# vim a.txt
提示:
"a.txt"
"a.txt" E212: 無法打開并寫入文件
請按 ENTER 或其它命令繼續
小結:這個是沒有用戶名和密碼的情況下,那么有用戶名和密碼怎么辦呢?請看下一小節
要求:需要輸入用戶名和密碼的才能訪問共享目錄,并且可讀可寫的
## 編輯配置文件
[root@wy ~]# vim /etc/samba/smb.conf
security = user
****在文件末尾
[wyylinux]
comment = share for users
path = /tmp/sambadir
browseable = yes
writable = yes
public = no
## 創建測試賬戶
[root@wy ~]# useradd smbuser1
解釋說明:
它的密碼是不需要定義的,因為我們登錄samba服務并不是用系統的用戶名和密碼,但有一點要明白,這個samba服務登錄的時候用的用戶名和系統的用戶名是相同的,但是實際上我們這個smbuser1只是映射過來的,它只是系統用戶的一個映射而已
## pdbedit工具增加用戶
[root@wy ~]# pdbedit -a smbuser1
new password:
retype new password:
解釋說明:
-a 就是add
-x 就是刪除
-h 查看這個工具有哪些選項
## 重啟服務
[root@wy ~]# /etc/init.d/smb restart
windows下的訪問
##打開運行
## 回車后,輸入測試賬號與密碼
## 可查看到共享的目錄模塊名
## 可以在共享目錄下創建文件
## 保存時要選擇編碼,要不然在linux下看會亂碼
linux下的訪問
## 第一種方式登錄
[root@wy ~]# smbclient //192.168.219.129/wyylinux
Enter root's password:
session setup failed: NT_STATUS_LOGON_FAILURE
[root@wy ~]# smbclient -Usmbuser1 //192.168.219.129/wyylinux
Enter smbuser1's password:
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23-36.el6_8]
smb: \> ls
. D 0 Wed Nov 16 22:06:20 2016
.. D 0 Wed Nov 16 22:18:45 2016
test D 0 Wed Nov 16 22:06:20 2016
1.txt 1383 Wed Nov 16 22:06:05 2016
35418 blocks of size 524288. 25857 blocks available
解釋說明:
登錄時需要用-U指定用戶名
## 第二種方式掛載
## 掛載
[root@wy ~]# mount -t cifs -o username=smbuser1,password=123456 //192.168.219.129/wyylinux /opt
## 查看掛載
[root@wy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_wy-lv_root 18G 3.8G 13G 24% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 485M 34M 426M 8% /boot
//192.168.219.129/wyy 18G 3.8G 13G 24% /opt
//192.168.219.129/wyylinux 18G 3.8G 13G 24% /opt
## 卸載之前的,再重新掛載
[root@wy ~]# umount /opt
[root@wy ~]# umount /opt
[root@wy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_wy-lv_root 18G 3.8G 13G 24% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 485M 34M 426M 8% /boot
[root@wy ~]# mount -t cifs -o username=smbuser1,password=123456 //192.168.219.129/wyylinux /opt
[root@wy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_wy-lv_root 18G 3.8G 13G 24% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 485M 34M 426M 8% /boot
//192.168.219.129/wyylinux 18G 3.8G 13G 24% /opt
## 進入共享目錄下,測試能否創建新的文件
[root@wy ~]# cd /opt/
[root@wy opt]# ls
1.txt test
[root@wy opt]# cd test/
[root@wy test]# ls
2222.txt
[root@wy test]# touch 12.txt
[root@wy test]# ls
12.txt 2222.txt
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。