一、samba介绍
-
SMB(Server Message Block)协议实现文件共享,也称为CIFS(Common Internet File System )
-
是Windows和类Unix系统之间共享文件的一种协议
-
客户端主要是Windows;支持多节点同时挂载以及并发写入
-
主要用于windows和Linux下的文件共享、打印共享
-
实现匿名与本地用户文件共享
samba进程
- smbd进程 控制发布共享目录与权限、负责文件传输 TCP 139 445
- nmbd进程 用于名称解析 netbios UDP 137 138 ;基于NETBIOS协议获得计算机名称——>解析为相应IP地址,实现信息通讯
二、环境搭建
① 服务器端软件安装:yum -y install samba
② 创建共享目录
[root@sambaserver ~]# mkdir -p /samba/share
③修改配置文件修改配置文件
[smbshare]
comment = samba share
path = /samba/share
guest ok = no
writable = yes
④ 创建本地用户
创建本地用户
[root@sambaserver ~]# useradd user01
[root@sambaserver ~]# echo 123 | passwd --stdin user01
更改用户 user01 的密码 。
passwd:所有的身份验证令牌已经成功更新。
基于本地用户创建smb用户
[root@sambaserver ~]# smbpasswd -a user01
New SMB password: 000
Retype new SMB password: 000
Added user user01.
验证用户是否添加成功
[root@sambaserver ~]# pdbedit -L
user01:1004:
⑤将samba设置为开机自启动
[root@sambaserver ~]# systemctl enable nmb
Created symlink from /etc/systemd/system/multi-user.target.wants/nmb.service to /usr/lib/systemd/system/nmb.service.
[root@sambaserver ~]# systemctl enable smb
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
[root@sambaserver ~]# systemctl start nmb
[root@sambaserver ~]# systemctl start smb
**
samba客户端部署
**
一、查询软件是否安装
安装smb客户端
查看
[root@sambaclient ~]# rpm -qa | grep samba
samba-common-4.8.3-4.el7.noarch
samba-common-libs-4.8.3-4.el7.x86_64
samba-client-4.8.3-4.el7.x86_64
samba-client-libs-4.8.3-4.el7.x86_64
samba-libs-4.8.3-4.el7.x86_64
如果没有的话,需要安装
[root@sambaclient ~]# yum -y install samba-client
二、查看samba共享资源
[root@sambaclient ~]# smbclient -L 192.168.216.201 -U user01
Enter SAMBA\user01's password:
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
smbshare Disk samba share
IPC$ IPC IPC Service (Samba 4.9.1)
user01 Disk Home Directories
Reconnecting with SMB1 for workgroup listing.
Server Comment
--------- -------
Workgroup Master
--------- -------
SAMBA SAMBASERVER
三、访问共享目录
[root@sambaclient ~]# smbclient //192.168.216.201/smbshare -U user01
Enter SAMBA\user01's password:
Try "help" to get a list of possible commands.
smb: \> ?
? allinfo altname archive backup
blocksize cancel case_sensitive cd chmod
chown close del deltree 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 posix_whoami 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 utimes logoff ..
!
查看
smb: \> ls
. D 0 Tue Mar 24 17:54:15 2020
.. D 0 Tue Mar 24 17:33:10 2020
smb.txt N 0 Tue Mar 24 17:54:15 2020
52403200 blocks of size 1024. 46216656 blocks available
下载
smb: \> get smb.txt
getting file \smb.txt of size 0 as smb.txt (0.0 KiloBytes/sec) (average 0.0 KiloBytes/sec)
smb: \> exit
上传
smb: \> put nextgo.txt
NT_STATUS_ACCESS_DENIED opening remote file \nextgo.txt
smb: \> put nextgo.txt
putting file nextgo.txt as \nextgo.txt (2.5 kb/s) (average 2.5 kb/s)
smb: \> ls
. D 0 Tue Mar 24 17:57:47 2020
.. D 0 Tue Mar 24 17:33:10 2020
smb.txt N 0 Tue Mar 24 17:54:15 2020
nextgo.txt A 13 Tue Mar 24 17:57:47 2020
52403200 blocks of size 1024. 46216632 blocks availables
到此samba服务搭建完成。