一、搭建環境:
CentOS7.5 防火牆關閉狀態
二、安裝samba和介紹
1、samba安裝
yum -y install samba
2、samba登錄驗證模式,即samba的安全級別
驗證模式 | 介紹 | 備註 |
share | 匿名驗證模式 | |
user(默認) | 本地用戶驗證模式 | tdbsam該方式是使用一個數據庫文件來驗證,數據庫文件叫passdb.tab,可以通過pdbedit-a將系統用戶轉化成samba用戶。 |
別名 | 虛擬用戶驗證方式 |
3、user模式的相關命令
pdbedit -a username #新建samba用戶
pdbedit -x username #刪除samba用戶
pdbedit -L 列出samba用戶的列表,即讀取passdb.tdb數據庫文件
4、虛擬用戶模式
暫時省略,待寫
三、新建用戶
useradd -s /sbin/nologin hufeng #新建用戶hufeng,但是不能讓此用戶登陸系統
pdbedit -a hufeng #設置samba用戶密碼
如果你先前已經新建了用戶,可以在這裏vim /etc/passwd 更改是否能登入系統和定義家目錄。
pokes:x:1000:1000:pokes:/home/pokes:/bin/bash
yanyu:x:1001:1001::/home/yanyu:/sbin/nologin
hufeng:x:1002:1002::/home/hufeng:/sbin/nologin
/bin/bash 是允許登錄系統 /sbin/nologin 是不允許登入系統
四、配置文件修改
vim /etc/samba/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA #工作組或者域
security = user #用戶訪問的驗證方式
passdb backend = tdbsam #密碼驗證方式
printing = cups
printcap name = cups
load printers = yes #啓動時是否共享打印機
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S #只允許用戶訪問各自的home目錄,用戶間不能互訪
browseable = No
read only = No
inherit acls = Yes
writable = no #新增此項,不給寫入權限
[shuju]
comment = hufeng #文件夾描述
path = /home/data/ftp/hufeng #共享目錄
browseable = yes #讓他可以看到
writable = no #不給寫入權限
home是默認共享的家目錄,我們自定義了一個shuju 目錄,現在我們打開共享的話,會看到兩個文件夾: 家目錄+shuju
五、自定義共享文件夾
但是我們只想用戶使用shuju文件夾,那我們直接刪除homes選項,讓配置文件變成如下樣子:
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA #工作組或者域
security = user #用戶訪問的驗證方式
passdb backend = tdbsam #密碼驗證方式
printing = cups
printcap name = cups
load printers = yes #啓動時是否共享打印機
cups options = raw
[shuju]
comment = hufeng #文件夾描述
path = /home/data/ftp/hufeng #共享目錄
browseable = yes #讓他可以看到
writable = no #不給寫入權限
這樣就可以實現自定義共享文件夾。
需要注意的是:一般採用這種共享方式建議不要給寫入權限,員工都喜歡一鍵記住密碼,這樣的話要是中了勒索病毒,只要有寫入權限就會一起感染。所以共享訪問一般都不給寫入權限,要想寫入必須使用FTP寫入。除非是數據不重要。