smb服务
用途
实现 类unix与windows之间的文件共享
实现 打印机共享
工作原理
smb与nfs 局域网内的共享
smbd 负责文件传输与发布共享资源 TCP 139 445
nmbd 负责名称解析NetBios UDP 137 138
1.安装软件
[root@samba ~]# yum -y install samba samba-client
[root@samba ~]# yum -y install cifs-utils
2.查询软件列表
[root@samba ~]# rpm -ql samba |grep smbstatus
/usr/bin/smbstatus --smb连接状态
/usr/lib/systemd/system/nmb.service --启动脚本
/usr/lib/systemd/system/smb.service
/usr/sbin/nmbd
/usr/sbin/smbd
[root@samba ~]# rpm -ql samba-common |less
/etc/logrotate.d/samba
/etc/samba/smb.conf --主配置文件
/etc/sysconfig/samba
/usr/bin/pdbedit --查询smb用户 smb存在/etc/passwd
/usr/bin/testparm --检测语法
/var/lib/samba/private --存放smb密码
/var/log/samba --smb日志
[root@samba ~]# rpm -ql samba-client
/usr/bin/smbclient --smb远程登录工具
/usr/bin/smbpasswd --配置smb密码
3.了解samba配置文件的参数
[root@samba ~]# rpm -qd samba-common |grep 5
/usr/share/man/man5/lmhosts.5.gz
/usr/share/man/man5/smb.conf.5.gz
/usr/share/man/man5/smbpasswd.5.gz
[root@samba ~]# cat /etc/samba/smb.conf |grep -v ^# |grep -v ^$ |grep -v ^';'
[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
browseable = No --隐藏
read only = No --可读写 等于 read only = No
inherit acls = Yes
[printers] --共享名称
comment = All Printers --描述信息
path = /data/database/samba --共享目录
printable = Yes --打印选项
create mask = 0600
browseable = No --隐藏
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
配置samba服务 新建(授权)
[root@samba ~]# mkdir /data/database/samba -p
[root@samba ~]# chmod 777 /data/database/samba
发布目录
[root@samba ~]# rm -rf /etc/samba/smb.conf
[root@samba ~]# mv /etc/samba/smb.conf.example /etc/samba/smb.conf
[root@samba ~]# vim /etc/samba/smb.conf
=======================================
security = user
passdb backend = tdbsam
map to guest = Bad User (添加)
---------------------------
取消以下注释";"并修改
---------------------------
[public]
comment = This is smb share
path = /data/database/samba
public = yes
writable = yes
=======================================
启动服务
[root@samba ~]# systemctl start nmb.service
[root@samba ~]# systemctl start smb.service
[root@samba ~]# netstat -tnlp |grep smb
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 20938/smbd
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 20938/smbd
tcp6 0 0 :::139 :::* LISTEN 20938/smbd
tcp6 0 0 :::445 :::* LISTEN 20938/smbd
[root@samba ~]# netstat -unlp |grep nmb
udp 0 0 172.16.255.255:137 0.0.0.0:* 20931/nmbd
udp 0 0 172.16.1.101:137 0.0.0.0:* 20931/nmbd
udp 0 0 192.168.1.255:137 0.0.0.0:* 20931/nmbd
udp 0 0 192.168.1.248:137 0.0.0.0:* 20931/nmbd
udp 0 0 0.0.0.0:137 0.0.0.0:* 20931/nmbd
udp 0 0 172.16.255.255:138 0.0.0.0:* 20931/nmbd
udp 0 0 172.16.1.101:138 0.0.0.0:* 20931/nmbd
udp 0 0 192.168.1.255:138 0.0.0.0:* 20931/nmbd
udp 0 0 192.168.1.248:138 0.0.0.0:* 20931/nmbd
udp 0 0 0.0.0.0:138 0.0.0.0:* 20931/nmbd
开机自启动:
[root@samba ~]# systemctl enable nmb.service && systemctl enable smb.service
测试
Linux平台测试
[root@client ~]# yum -y install samba-client
发现对方共享资源
[root@client ~]# smbclient -L 172.16.1.101
Enter SAMBA\root's password:
Sharename Type Comment
--------- ---- -------
public Disk This is smb share
IPC$ IPC IPC Service (Samba Server Version 4.9.1)
Reconnecting with SMB1 for workgroup listing.
Server Comment
--------- -------
Workgroup Master
--------- -------
MYGROUP SAMBA
[root@client ~]# smbclient //172.16.1.101/public
Enter SAMBA\root's password: (密码为空)
Try "help" to get a list of possible commands.
smb: \>
新建目录
smb: \> mkdir abc
smb: \> ls
. D 0 Mon Sep 23 22:13:29 2019
.. D 0 Mon Sep 23 21:59:26 2019
abc D 0 Mon Sep 23 22:13:29 2019
52402180 blocks of size 1024. 52369092 blocks available
smb: \>
临时挂载
[root@samba ~]# mount -t cifs //172.16.1.101/public /mnt/
Password for root@//172.16.1.101/public: ******
查看挂载是否成功
[root@samba ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.5G 16G 9% /
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 14M 473M 3% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sdb1 50G 33M 50G 1% /data
/dev/sda1 1014M 133M 882M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
//172.16.1.101/public 50G 33M 50G 1% /mnt
Windows测试
录入\\192.168.1.248