Samba服务
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Samba服务相关的知识,希望对你有一定的参考价值。
samba简介
Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成。SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务。SMB协议是客户机/服务器型协议,客户机通过该协议可以访问服务器上的共享文件系统、打印机及其他资源。通过设置“NetBios over TCP/IP”使得Samba不但能与局域网络主机分享资源。
samba监听端口:
TCP | UDP |
---|---|
139 | 137 |
445 | 138 |
tcp端口对应的服务是smbd服务,其作用是提供对服务器中文件,打印资源的共享访问。
udp端口对应的服务是nmbd服务,其作用是提供基于NetBOIS主机名称的解析。
进程 | 对应 |
---|---|
nmbd | 对应netbois |
smbd | 对应cifs协议 |
Samba 服务配置
服务端ip | 客户端ip |
---|---|
192.168.47.11 | 192.168.47.12 |
关闭防火墙
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# setenforce 0安装Samba服务程序
[[email protected] ~]# yum install samba*
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
启动Samba服务程序
[[email protected] ~]# systemctl start smb
设置Samba服务随系统启动而启动
[[email protected] ~]# systemctl enable smb
创建映射共享目录
创建用户dd
[[email protected] ~]# useradd -M dd
为dd用户创建smb共享密码
[[email protected] ~]# smbpasswd -a dd
New SMB password:
Retype new SMB password:
Added user dd.
假设这里映射dd用户为share用户,那么就要在/etc/samba/smbusers文件中添加内容
[[email protected] ~]# echo ‘dd = share‘ > /etc/samba/smbusers
[[email protected] ~]# vim /etc/samba/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run ‘testparm‘ to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA
security = user
username map = /etc/samba/smbusers // 添加此行内容
passdb backend = tdbsam
创建一个共享目录yan
[[email protected] ~]# mkdir /opt/yan
[[email protected] ~]# chown -R dd.dd /opt/yan/
[[email protected] ~]# ll /opt/
总用量 0
drwxr-xr-x. 2 dd dd 6 8月 7 19:30 yan
drwxr-xr-x. 9 root root 254 7月 16 15:51 yanyinglai
配置共享
[[email protected] ~]# cat >> /etc/samba/smb.conf <<EOF
[yan] 共享名
comment = this is 描述信息,任意字符串
path = /opt/yan/ 共享目录路径browseable = yes 指定该共享是否可以浏览
guest ok = yes 表示设置是否所有人均可访问共享目录
writable = yes 指定该共享路径是否可写
write list = share 表示设置允许写的用户和组public = yes 表示设置是否允许匿名用户访问
EOF
[[email protected] ~]# tail -8 /etc/samba/smb.conf
[yan]
comment = this is
path = /opt/yan/
browseable = yes
guest ok = yes
writable = yes
write list = share
public = yes
testparm
测试配置文件是否有语法错误,以及显示最终生效的配置
[[email protected] ~]# 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$]"
Processing section "[yan]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
重新启动smb服务
重新启动smb服务
[[email protected] ~]# systemctl restart smb
重新加载smb服务
[[email protected] ~]# systemctl reload smb
在客户机查看samba服务器有哪些共享资源
yum查找smbclient软件包的绝对路径
[[email protected] ~]# yum provides *bin/smbclient
[[email protected] ~]# yum install /usr/bin/smbclient -y
在客户端查看samba服务器有哪些共享资源
[[email protected] ~]# smbclient -L 192.168.47.11 -U share
Enter SAMBAshare‘s password:
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
yan Disk this is
IPC$ IPC IPC Service (Samba 4.6.2)
dd Disk Home Directories
Reconnecting with SMB1 for workgroup listing.
Server Comment
--------- -------
Workgroup Master
--------- -------
将samba服务器的共享资源yan挂载到客户机本地
[[email protected] ~]# mkdir /opt/smb
[[email protected] ~]# mount -t cifs //192.168.47.11/yan /opt/smb -o username=share,password=123
[[email protected] ~]# df-h
-bash: df-h: 未找到命令
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.6M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 125M 890M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
//192.168.47.11/yan 47G 5.0G 42G 11% /opt/smb
验证
在客户端上进入共享目录创建新文件
[[email protected] ~]# cd /opt/smb
[[email protected] smb]# touch abc
[[email protected] smb]# mkdir dfc
[[email protected] smb]# ls
abc dfc
在服务端查看共享的目录里面是否存在客户端创建的文件和目录
[[email protected] ~]# cd /opt/yan/
[[email protected] yan]# ls
abc dfc
匿名共享
服务器ip | 客户端ip |
---|---|
192.168.47.11 | 192.168.47.12 |
配置匿名共享时,还是需要关闭防火墙
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# setenforce 0
使用yum命令安装samba服务器
[[email protected] ~]# yum install samba*
[[email protected] ~]# vim /etc/samba/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run ‘testparm‘ to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA
security = user
map to guest = Bad User 然后在全局配置中添加内容 固定式
passdb backend = tdbsam
创建一个共享目录,创建目录名为yan
[[email protected] ~]# mkdir /opt/yan
[[email protected] ~]# chmod 777 /opt/yan/
[[email protected] ~]# ll /opt/
总用量 0
drwxrwxrwx. 2 root root 6 8月 7 20:28 yan
drwxr-xr-x. 9 root root 254 7月 16 15:51 yanyinglai
配置共享
[[email protected] ~]# cat >> /etc/samba/smb.conf <<EOF
[yan]
comment = yan
path = /opt/yan
browseable = yes
guest ok = yes
writable = yes
public = yes
EOF
启动smb服务:
[[email protected] ~]# systemctl start smb
[[email protected] ~]# systemctl restart smb
在客户端查看samba服务器有哪些共享资源
[[email protected] ~]# smbclient -L192.168.47.11 -U ‘Bad User‘
Enter SAMBABad User‘s password:
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
yan Disk yan
IPC$ IPC IPC Service (Samba 4.6.2)
Reconnecting with SMB1 for workgroup listing.
Server Comment
--------- -------
Workgroup Master
--------- -------
将samba服务器的共享资源yan挂载到客户机本地
[[email protected] ~]# mkdir /opt/smb
[[email protected] ~]# mount -t cifs //192.168.47.11/yan /opt/smb -o username=‘Bad User‘
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 125M 890M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
//192.168.47.11/yan 47G 5.0G 42G 11% /opt/smb
在客户端上进入共享目录创建文件或目录验证一下,并在服务器上查看客户端创建的文件
客户端
[[email protected] ~]# cd /opt/smb
[[email protected] smb]# touch qwer
[[email protected] smb]# mkdir qazs
服务器
[[email protected] ~]# cd /opt/yan/
[[email protected] yan]# ls
qazs qwer
以上是关于Samba服务的主要内容,如果未能解决你的问题,请参考以下文章