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/
安全