一、基础概念
Samba是一种实现SMB(Server Messages Block,信息服务块)协议的开源软件,主要用于Samba是一种实现SMB(Server Messages Block,信息服务块)协议的开源软件,主要用于在Linux和Windows之间进行文件和打印机等资源的共享。它是基于Client/Server型的协议,允许Linux系统的文件和打印服务与Windows用户进行资源共享。Samba的核心守护进程是smbd和nmbd。
二、需求场景
Samba服务端:192.168.1.132 Centos 8.8系统
Samba服务端:192.168.1.132 Centos 8.8系统
三、Samba服务端配置
1、服务安装
yum -y install samba samba-client
systemctl start smb nmb
systemctl status smb nmb
systemctl enable smb nmb
ps -ef | grep -E 'smb|nmb'
netstat -tunlp | grep -E 'smbd|nmbd'
Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled)Active: active (running) since Fri 2024-01-05 15:52:35 CST; 14min agoDocs: man:smbd(8)man:samba(7)man:smb.conf(5)Main PID: 62713 (smbd)Status: "smbd: ready to serve connections..."Tasks: 4 (limit: 12150)Memory: 5.9MCGroup: /system.slice/smb.serviceLoaded: loaded (/usr/lib/systemd/system/nmb.service; disabled; vendor preset: disabled)Active: active (running) since Fri 2024-01-05 15:52:35 CST; 14min agoDocs: man:nmbd(8)man:samba(7)man:smb.conf(5)root 62713 1 0 15:52 ? 00:00:00 /usr/sbin/smbd --foreground --no-process-grouproot 62715 1 0 15:52 ? 00:00:00 /usr/sbin/nmbd --foreground --no-process-grouproot 62717 62713 0 15:52 ? 00:00:00 /usr/sbin/smbd --foreground --no-process-grouproot 62718 62713 0 15:52 ? 00:00:00 /usr/sbin/smbd --foreground --no-process-grouproot 63306 62713 0 15:59 ? 00:00:00 /usr/sbin/smbd --foreground --no-process-grouproot 63956 63855 0 16:07 pts/1 00:00:00 grep --color=auto -E smb|nmbtcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 62713/smbdtcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 62713/smbdtcp6 0 0 :::445 :::* LISTEN 62713/smbdtcp6 0 0 :::139 :::* LISTEN 62713/smbdudp 0 0 172.17.255.255:137 0.0.0.0:* 62715/nmbdudp 0 0 172.17.0.1:137 0.0.0.0:* 62715/nmbdudp 0 0 172.18.255.255:137 0.0.0.0:* 62715/nmbdudp 0 0 172.18.0.1:137 0.0.0.0:* 62715/nmbdudp 0 0 192.168.1.255:137 0.0.0.0:* 62715/nmbdudp 0 0 192.168.1.132:137 0.0.0.0:* 62715/nmbdudp 0 0 0.0.0.0:137 0.0.0.0:* 62715/nmbdudp 0 0 172.17.255.255:138 0.0.0.0:* 62715/nmbdudp 0 0 172.17.0.1:138 0.0.0.0:* 62715/nmbdudp 0 0 172.18.255.255:138 0.0.0.0:* 62715/nmbdudp 0 0 172.18.0.1:138 0.0.0.0:* 62715/nmbdudp 0 0 192.168.1.255:138 0.0.0.0:* 62715/nmbdudp 0 0 192.168.1.132:138 0.0.0.0:* 62715/nmbdudp 0 0 0.0.0.0:138 0.0.0.0:* 62715/nmbd

2、创建用户与目录
mkdir -p /storage/shareduseradd -s /sbin/nologin adminuseradd -g admin -s /sbin/nologin usersmbpasswd -a adminsmbpasswd -a user
3、设置目录权限属性
cd /storage/lschown admin.admin sharedchmod -R 777 shared
4、修改服务配置文件
vi /etc/samba/smb.conf
[global]workgroup = SC.LOCALserver string = Samba Server Version %vnetbios name = Linuxidc-Serverlog file = /var/log/samba/%m.logmax log size = 10240security = userpassdb backend = tdbsam[shared]# 共享文件目录描述comment = Shared Directories# 共享文件目录path = /storage/shared/# 是否允许guest访问public = no# 指定管理用户admin users = admin# 可访问的用户组、用户valid users = @admin# 是否浏览权限browseable = yes# 是否可写权限writable = yes# 文件权限设置create mask = 0777directory mask = 0777force directory mode = 0777force create mode = 0777
5、重启服务、确认防火墙都已放行、SeLinux处于放行状态
systemctl restart smb nmb6、服务验证
smbstatus
[root@Master storage]# smbstatusSamba version 4.17.5PID Username Group Machine Protocol Version Encryption Signing----------------------------------------------------------------------------------------------------------------------------------------66086 admin admin 192.168.1.139 (ipv4:192.168.1.139:36756) SMB3_11 - partial(AES-128-CMAC)Service pid Machine Connected at Encryption Signing---------------------------------------------------------------------------------------------shared 66086 192.168.1.139 五 1月 5 16时36分18秒 2024 CST - -No locked files
二、Samba客户端连接测试
1、安装客户端工具
yum install samba-client2、连接测试
smbclient //192.168.1.132/shared -U admin然后输入密码进入-U 指定用户名/shared 共享模块

3、下载文件测试
下载: get 文件名
[root@Node47 dc]# smbclient //192.168.1.132/shared -U adminEnter SAMBAadmin's password:Try "help" to get a list of possible commands.smb: > getget [localname]smb: > get 1getting file 1 of size 0 as 1 (0.0 KiloBytes/sec) (average 0.0 KiloBytes/sec)
上传:put 文件名
Enter SAMBAadmin's password:Try "help" to get a list of possible commands.smb: > put 22 does not existsmb: > put 2smb: > put 2.txtputting file 2.txt as 2.txt (5.2 kb/s) (average 5.2 kb/s)
多个上传: mput *
Enter SAMBAadmin's password:Try "help" to get a list of possible commands.smb: > put 22 does not existsmb: > put 2smb: > put 2.txtputting file 2.txt as 2.txt (5.2 kb/s) (average 5.2 kb/s)smb: > mput *Put file 2.txt? yputting file 2.txt as 2.txt (7.8 kb/s) (average 6.2 kb/s)Put file 2? yputting file 2 as 2 (0.0 kb/s) (average 5.2 kb/s)Put file 1? yputting file 1 as 1 (0.0 kb/s) (average 4.5 kb/s)

