SMB(Server Messages Block,信息服务块)是一种在==局域网(默认)==上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务。SMB协议是客户机/服务器型(c/s)协议,客户机通过该协议可以访问服务器上的共享文件系统、打印机及其他资源。
1)ftp的优缺点:
2)samba的特性:
samba产生的比较早,目的就是为了跨平台实现文件共享。
随着互联网的发展,微软希望将samba可以在互联网上传输,就把samba协议进行整合,变成了一种网络文件系统cifs(Common Internet File System )。主要功能就是文件共享,只是互联网进行文件共享。
cifs是公开的或者开放的SAM版本协议。
一般我们在互联网依旧是使用FTP,在局域网还是使用samba比较多。
1)协议:
2)软件:
3)服务:
4)使用端口:
5)配置文件:
1)share匿名验证:不需要账户名和密码直接使用
2)user本地用户验证:
3)别名用户(虚拟用户):防止对本地用户干扰
1)[global]
:全局设置,用于定义服务器的整体特性,其配置项对所有生产资源生效。
[global]
workgroup = MYGROUP # 要加入的工作组或域
server string = Samba Server Version %v # 说明版本,%v自动获取版本
interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24 # 默认监听的网卡,或者IP地址
hosts allow = 192.168.12. EXCEPT 192.168.12.20 # 访问控制,允许那些客户端连接,整个192.168.12.都可以访问,除了192.168.12.20这个客户。
hosts deny = 127. 192.168.12. 192.168.13. # 拒绝访问
log file = /var/log/samba/log.%m # 日志文件的位置(填写具体的位置,%m主机的主即命,即每一个用户会产生资金的独立日志)
max log size = 50 # 单个日志文件的大小
security = user # 验证方式,安全级别,默认是本地用户
passdb backend = tdbsam # 默认验证samba用户的机制
load printers = yes # 是否加载共享打印机
2)[homes]
(特殊共享):用于所有创建了的samba账户进行共享,不用单独设置,使用同一个共享模版。
[homes] # 共享名就写homes,统一指代每一个用户对应的家目录,每个用户只能登录到自己家目录的共享
comment = Home Directories # 描述,随便写
browseable = no # 是否将共享出去的资源是否可见,如果为yes一个用户可以看到所有用户的家目录
writable = yes # 是否可以向该共享内写入内容。注意:还需要文件系统允许目录被写入。
; valid users = %S # 允许访问该共享的用户有那些,bob(允许bob用户),@bob(允许bob用户组)
3)[printers]
(特殊共享):将打印资源共享出去
[printers]
comment = All Printers
path = /var/spool/samba # 共享设备的路径
browseable = no
guest ok = no # 是否允许匿名访问
writable = no # 是否可写
printable = yes # 是否可打印
4)[自定义]
:自定义共享区域
[自定义] # 访问IP后的地址名
; comment = Public Stuff
; path = /home/samba # 共享路径
; public = yes # 是否允许匿名访问
; browseable = no # 是否可见
; writable = no # 是否可写
5)配置文件检查工具:
testparm:检查配置文件的语法是否正确。
-v:显示samba所有支持的选项。
[root@smb-server samba]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[print$]"
Loaded services file OK. # 表示语法正确。
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
# Global parameters
[global]
workgroup = SAMBA
printcap name = cups
security = USER
idmap config * : backend = tdb
cups options = raw
[homes]
comment = Home Directories
browseable = No
inherit acls = Yes
read only = No
valid users = %S %D%w%S
[printers]
comment = All Printers
path = /var/tmp
browseable = No
printable = Yes
create mask = 0600
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
create mask = 0664
directory mask = 0775
write list = root
写入权限的控制方式(类似于vsftpdde限制方式):
1)配置文件开启,文件系统严格控制
2)文件系统开启,配置文件严格控制
实验准备:
1)服务端安装samba服务:
[root@smb-server ~]# yum install samba -y
Installed:
samba.x86_64 0:4.4.4-9.el7
Dependency Installed:
pytalloc.x86_64 0:2.1.6-1.el7
samba-common-libs.x86_64 0:4.4.4-9.el7
samba-common-tools.x86_64 0:4.4.4-9.el7
samba-libs.x86_64 0:4.4.4-9.el7
Complete!
2)启动服务:
[root@smb-server ~]# systemctl start smb.service
3)添加samba用户song:
[root@smb-server ~]# useradd -s /sbin/nologin song # 添加一个不可登录系统的用户
[root@smb-server ~]# pdbedit -a song # 将它设置为samba用户,添加密码
new password: # 输入密码
retype new password: # 输入成功
Unix username: song
NT username:
Account Flags: [U ]
User SID: S-1-5-21-1225432830-2015567474-4056693890-1000
Primary Group SID: S-1-5-21-1225432830-2015567474-4056693890-513
Full Name:
Home Directory: \\smb-server\song
HomeDir Drive:
Logon Script:
Profile Path: \\smb-server\song\profile
Domain: SMB-SERVER
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: Wed, 06 Feb 2036 23:06:39 CST
Kickoff time: Wed, 06 Feb 2036 23:06:39 CST
Password last set: Sun, 23 Aug 2020 12:27:17 CST
Password can change: Sun, 23 Aug 2020 12:27:17 CST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
4)添加samba用户liu:
[root@smb-server samba]# useradd -s /sbin/nologin liu
[root@smb-server samba]# pdbedit -a liu
new password:
retype new password:
Unix username: liu
NT username:
Account Flags: [U ]
User SID: S-1-5-21-1225432830-2015567474-4056693890-1001
Primary Group SID: S-1-5-21-1225432830-2015567474-4056693890-513
Full Name:
Home Directory: \\smb-server\liu
HomeDir Drive:
Logon Script:
Profile Path: \\smb-server\liu\profile
Domain: SMB-SERVER
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: Wed, 06 Feb 2036 23:06:39 CST
Kickoff time: Wed, 06 Feb 2036 23:06:39 CST
Password last set: Sun, 23 Aug 2020 13:54:25 CST
Password can change: Sun, 23 Aug 2020 13:54:25 CST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
1)安装客户端命令:
[root@client1 ~]# yum whatprovides smbclient
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel7.3/filelists_db | 3.3 MB 00:00
samba-client-4.4.4-9.el7.x86_64 : Samba client programs
Repo : rhel7.3
Matched from:
Filename : /usr/bin/smbclient
[root@client1 ~]# yum install samba-client-4.4.4-9.el7.x86_64 -y
Installed:
samba-client.x86_64 0:4.4.4-9.el7
Dependency Installed:
samba-common-libs.x86_64 0:4.4.4-9.el7
Complete!
2)查看服务器共享song(只看到song):
[root@client1 ~]# smbclient -U song -L //172.25.5.10
Enter song's password:
Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
IPC$ IPC IPC Service (Samba 4.4.4)
song Disk Home Directories # 有song用户
Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]
Server Comment
--------- -------
Workgroup Master
--------- -------
3)查看服务器共享liu(只看到liu):这就是homes的特殊性browseable = no
[root@client1 ~]# smbclient -U liu -L //172.25.5.10
Enter liu's password:
Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
IPC$ IPC IPC Service (Samba 4.4.4)
liu Disk Home Directories
Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]
Server Comment
--------- -------
Workgroup Master
--------- -------
4)登录liu服务器共享:
[root@client1 ~]# smbclient -U liu //172.25.5.10/liu
Enter liu's password:
Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]
smb: \> ls
. D 0 Sun Aug 23 13:54:07 2020
.. D 0 Sun Aug 23 13:54:07 2020
.mozilla DH 0 Thu May 14 10:24:21 2020
.bash_logout H 18 Tue Jul 12 23:17:09 2016
.bash_profile H 193 Tue Jul 12 23:17:09 2016
.bashrc H 231 Tue Jul 12 23:17:09 2016
4597760 blocks of size 1024. 1435020 blocks available
5)都是自定义命令:
smb: \> ?
? allinfo altname archive backup
blocksize cancel case_sensitive cd chmod
chown close del dir du
echo exit get getfacl geteas
hardlink help history iosize lcd
link lock lowercase ls l
mask md mget mkdir more
mput newer notify open posix
posix_encrypt posix_open posix_mkdir posix_rmdir posix_unlink
print prompt put pwd q
queue quit readlink rd recurse
reget rename reput rm rmdir
showacls setea setmode scopy stat
symlink tar tarmode timeout translate
unlock volume vuid wdel logon
listconnect showconnect tcon tdis tid
logoff .. !
6)上传文件:
smb: \> put anaconda-ks.cfg
putting file anaconda-ks.cfg as \anaconda-ks.cfg (111.2 kb/s) (average 111.2 kb/s)
smb: \> ls
. D 0 Sun Aug 23 13:59:00 2020
.. D 0 Sun Aug 23 13:54:07 2020
.mozilla DH 0 Thu May 14 10:24:21 2020
.bash_logout H 18 Tue Jul 12 23:17:09 2016
.bash_profile H 193 Tue Jul 12 23:17:09 2016
.bashrc H 231 Tue Jul 12 23:17:09 2016
anaconda-ks.cfg A 2050 Sun Aug 23 13:59:00 2020
4597760 blocks of size 1024. 1435028 blocks available
7)服务端查看,文件已存在:
[root@smb-server samba]# cd /home/liu/
[root@smb-server liu]# ls
anaconda-ks.cfg
[root@smb-server liu]# ll
total 4
-rwxr--r-- 1 liu liu 2050 Aug 23 13:59 anaconda-ks.cfg