cenos6.4 samba配置

samba安裝
[root@s01 ~]# yum install samba.x86_64 samba-client.x86_64 samba-common.x86_64
nmb:管理工做羣組,netbios name等解析,利用upd協議(137,138端口)來負責名稱解析的任務
smb:管理主機分享的目錄與打印機等,利用tcp來傳輸共享文件,利用端口tcp協議(139,445端口)
linux


[global]---全局設置
security=share/user/server/domain

share:不須要用戶名和密碼
user:需用戶名和密碼
server: 用戶名和密碼在指定的一臺samba上驗證,驗證錯誤,客戶端會用user級別訪問
domain:服務器加入window域環境,驗證工做由windows域控制器負責。
ads:使用ads安全級別加入到windows域環境中,包含有domain級別中的全部功能,而且能夠具有域控制器的功能。

ios

###配置文件
vim /etc/samba/smb.conf
[global]
//日誌文件目錄
log file = /var/log/samba/log.%m    
# max 50KB per log file, then rotate
//日誌切割大小
max log size = 50
//安全級別share/user
security = user
config file               ---定義子配置文件

hosts allow/hosts deny    ---容許/拒絕某些主機訪問,寫在[global]裏面對全局生效,
              ---寫在自定義共享目錄,只對單個目錄生效

//自定義共享目錄
[public]                  ---共享目錄名稱  //10.10.54.226/public
comment = Public Stuff    ---標識
path = /home/samba        ---服務器端共享目錄的存儲路徑
public = yes /guest ok = yes  ---是否容許匿名用戶訪問
writable = yes /read only = yes  ---是否具備寫入權限
write list = +user_name,@group_name ---指定那些用戶或者用戶組可寫
browseable = no           ---共享目錄是否可見(no爲隱藏,yes可見)
         
####若是security = share public = no 以局部爲準
####若是writable=yes  read only=yes 同時出現 最後出現的那個設置值爲主要設置
####當host deny和hosts allow字段同時出現並定義滴內容相互衝突時,hosts allow優先vim

//賬號映射配置
vim /etc/samba/smbusers
banqk = ccc
//ccc 不是系統用戶也不是samba用戶windows

##############################################################
centos

四.創建共享目錄爲centos,其絕對路徑爲/share/centos,只有boss賬號能夠讀寫該目錄,其餘人只能讀取
######
1.vim /etc/samba/smb.conf
//註釋掉[homes]和[printers]
:249,262s/^/;/g


[global]
security = user
[centos]
comment = centos
path = /share/centos
public = no
browseable = yes
read only = yes
write list = boss
###################################
或者
vim /etc/samba/smb.conf
//註釋掉[homes]和[printers]
:249,262s/^/;/g


[global]
security = user
config file = /etc/samba/smb.conf.%U

[centos]
comment = centos
path = /share/centos
public = no
browseable = yes
read only = yes
//配置boss文件
vim /etc/samba/smb.conf.boss
//註釋掉[homes]和[printers]
:249,262s/^/;/g


[global]
security = user

[centos]
comment = centos
path = /share/centos
public = no
browseable = yes
write list = +boss

2.檢查配置文件
[root@Cent64 ~]# testparm -v
3.啓動服務
[root@Cent64 ~]# /etc/init.d/nmb start
[root@Cent64 ~]# /etc/init.d/smb start
[root@Cent64 ~]# chkconfig nmb on
[root@Cent64 ~]# chkconfig smb on
4.觀察端口
[root@Cent64 ~]# netstat -nulpt
5.建立linux用戶
[root@Cent64 ~]# useradd boss
[root@Cent64 ~]# id boss
root@Cent64 ~]# groupadd users
[root@Cent64 ~]# useradd -g users ww
[root@Cent64 ~]# useradd -g users sl
6.建立samba用戶
[root@Cent64 ~]# pdbedit -a -u boss
[root@Cent64 ~]# pdbedit -a -u ww
[root@Cent64 ~]# pdbedit -a -u sl
[root@Cent64 ~]# pdbedit -L
sl:507:
ww:506:
boss:504:
7.建立目錄
[root@Cent64 share]# mkdir centos
[root@Cent64 share]# chmod 757 centos/

8.//測試是否鏈接
smbclient -L ip_address [-U 用戶賬號]
[root@Cent64 ~]# smbclient -L 10.10.54.64 不能訪問
[root@Cent64 share]# smbclient -L 10.10.54.64 -U boss
[root@Cent64 share]# smbclient -L 10.10.54.64 -U ww
[root@Cent64 ~]# smbclient //10.10.54.64/centos -Uboss
Enter boss's password:
Domain=[SHIWEI.SSR] OS=[Unix] Server=[Samba 3.6.9-151.el6]
smb: \>
smb: \> mkdir 57
//建文件失敗,沒有權限
NT_STATUS_ACCESS_DENIED making remote directory \57
[root@Cent64 smb]# ls -dl /share/centos
//當前以samba用戶boss登陸,與系統用戶root無關,boss沒有寫的權限
drwxr-xrwx 4 root boss 4096 3月   4 14:22 /share/centos
//修改boss改成第三方權限
[root@Cent64 ~]# chown root.root /share/centos/ -R
或者chmod 775 /share/centos/

#訪問方式
\\10.10.54.64/share/centos      ---window

smb://10.10.54.64/share/centos   ---linux
9.掛載
[root@Cent64 centos]# mount -t cifs //10.10.54.64/centos /mnt/smb/ -o username=boss,password=123
[root@Cent64 centos]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2              6192704   1584516   4293616  27% /
tmpfs                   510268         0    510268   0% /dev/shm
/dev/sda1               198337     25836    162261  14% /boot
/dev/sda5               516040     16780    473048   4% /swap
/dev/sda3              5160576   4368728    529704  90% /usr
//10.10.54.64/centos   6192704   1584516   4293616  27% /mnt/smb


10.測試可寫
[root@Cent64 /]# cd /mnt/
[root@Cent64 mnt]# chmod 757 /share/centos

[root@Cent64 mnt]# touch aa
[root@Cent64 mnt]# ll
total 376876
-rw-r--r-- 1 nobody nobody         0 3月   3 19:44 aa
卸載
umount /mnt/smb
//用戶和用戶組爲nobody
11.換個用戶掛載
[root@Cent64 ~]# mount -t cifs //10.10.54.64/centos /tmp -o username=ww
[root@Cent64 tmp]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2              6192704   1584560   4293572  27% /
tmpfs                   510268         0    510268   0% /dev/shm
/dev/sda1               198337     25836    162261  14% /boot
/dev/sda5               516040     16780    473048   4% /swap
/dev/sda3              5160576   4368728    529704  90% /usr
//10.10.54.64/centos   6192704   1584560   4293572  27% /tmp
//建立文件失敗
[root@Cent64 tmp]# touch a
touch: cannot touch `a': Permission denied
卸載
[root@Cent64 smb]# umount /tmp/

安全

相關文章
相關標籤/搜索