ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Samba服务器配置(实例解析)

2021-09-25 17:31:10  阅读:153  来源: 互联网

标签:Samba share textshare samba 实例 服务器 root smb localhost


Samba服务器配置(实例解析)

一、在rhel 8 上配置samba共享服务器

① 查看samba包信息

[root@localhost ~]# yum info samba				#查看samba包信息
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:46:48 ago on Mon 21 Dec 2020 12:31:15 AM EST.
Available Packages
Name         : samba
Version      : 4.12.3
Release      : 12.el8.3
Architecture : x86_64
Size         : 840 k
Source       : samba-4.12.3-12.el8.3.src.rpm
Repository   : base
Summary      : Server and Client software to interoperate with Windows machines
URL          : https://www.samba.org
License      : GPLv3+ and LGPLv3+
Description  : Samba is the standard Windows interoperability suite of programs for Linux
             : and Unix.

② 安装Samba服务 设置开机自启

[root@localhost ~]# yum install -y samba 	   #安装samba服务
[root@localhost ~]# rpm -qa | grep samba	   #查看samba包
samba-client-libs-4.12.3-12.el8.3.x86_64
samba-common-4.12.3-12.el8.3.noarch
samba-libs-4.12.3-12.el8.3.x86_64
samba-common-tools-4.12.3-12.el8.3.x86_64
samba-4.12.3-12.el8.3.x86_64
samba-common-libs-4.12.3-12.el8.3.x86_64

[root@localhost ~]# systemctl start smb       	#启动samba服务
[root@localhost ~]# systemctl enable smb		#设置开机自启
Created symlink /etc/systemd/system/multi-user.target.wants/smb.service /usr/lib/systemd/system/smb.service.
[root@localhost ~]# systemctl status smb		#查看服务正在运行
● smb.service - Samba SMB Daemon
   Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-12-21 01:22:27 EST; 21s ago
     Docs: man:smbd(8)
           man:samba(7)
           man:smb.conf(5)
 Main PID: 33908 (smbd)
   Status: "smbd: ready to serve connections..."
    Tasks: 4 (limit: 12180)
   Memory: 13.7M
   CGroup: /system.slice/smb.service
           ├─33908 /usr/sbin/smbd --foreground --no-process-group
           ├─33910 /usr/sbin/smbd --foreground --no-process-group
           ├─33911 /usr/sbin/smbd --foreground --no-process-group
           └─33912 /usr/sbin/smbd --foreground --no-process-group

在这里插入图片描述

③ 建立测试共享目录添加相应的用户和组,添加对应的samba账号

[root@localhost ~]# mkdir /textshare											
[root@localhost ~]# mkdir /textshare/share						  #添加共享文件夹
[root@localhost ~]# touch /textshare/share/text_share.tar		  #添加共享测试文件

[root@localhost ~]# groupadd share							#添加用户组 share
[root@localhost ~]# useradd -g share share1					#添加 用户share1 和share2
[root@localhost ~]# useradd -g share share2
[root@localhost ~]# passwd share1					        # 给用户share1与share2 设立密码
Changing password for user share1.
New password: 												# passwd: 111111  (测试用)
BAD PASSWORD: The password is a palindrome
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd share2
Changing password for user share2.
New password: 												# passwd: 111111  (测试用)	
BAD PASSWORD: The password is a palindrome
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost ~]# smbpasswd -a share1						# 建立于系统中同名的samba账号
New SMB password:											# passwd: 111111  (测试用)
Retype new SMB password:
Added user share1.
[root@localhost ~]# smbpasswd -a share2										
New SMB password:											# passwd: 111111  (测试用)
Retype new SMB password:
Added user share2.

④ 修改smb.conf

[root@localhost ~]# vim /etc/samba/smb.conf
[share]										# 定义共享文件 目录要求
	comment = share						    # 注释说明 文件名为share
	path = /textshare/share					# 分享文件的路径(绝对路径地址)
	writable = yes							# 是否可以读写
	browseable = yes						# 指定该共享是否可以浏览 
	valid users = @share					# 允许访问该共享的用户 @share
											# invalid users = 禁止访问该共享的用户

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lanYSr01-1632561246673)(C:\Users\1\AppData\Roaming\Typora\typora-user-images\image-20201221165850058.png)]

comment注释说明
path分享资源的完整路径名称,除了路径要正确外,目录的权限也要设对(绝对路径)
browseable是yes/否no在浏览资源中显示共享目录,若为否则必须指定共享路径才能存取
printable是yes/否no允许打印
hide dot ftles是yes/否no隐藏隐藏文件
public是yes/否no 公开共享,若为否则进行身份验证(只有当security = share 时此项才起作用)
guest ok是yes/否no 公开共享,若为否则进行身份验证(只有当security = share 时此项才起作用)
read only是yes/否no 以只读方式共享当与writable发生冲突时也writable为准
writable是yes/否no可写 不以只读方式共享 当与read only发生冲突时,无视read only
vaild users设定只有此名单内的用户才能访问共享资源(拒绝优先)(用户名/@组名)
invalid users设定只有此名单内的用户不能访问共享资源(拒绝优先)(用户名/@组名)
read list设定此名单内的成员为只读(用户名/@组名)
write list若设定为只读时,则只有此设定的名单内的成员才可作写入动作(用户名/@组名)
create mask建立文件时所给的权限
directory mask建立目录时所给的权限
force group指定存取资源时须以此设定的群组使用者进入才能存取(用户名/@组名)
force user指定存取资源时须以此设定的使用者进入才能存取(用户名/@组名)
allow hosts设定只有此网段/IP的用户才能访问共享资源
allwo hosts网段 except IP
deny hosts设定只有此网段/IP的用户不能访问共享资源
allow hosts本网段指定IP指定IP
deny hosts指定IP本网段指定IP

⑤ 修改共享目录本地系统权限

[root@localhost textshare]# chmod 777 /textshare/share/ -R
[root@localhost textshare]# chown share1:share /textshare/share/ -R
[root@localhost textshare]# chown share2:share /textshare/share/ -R
[root@localhost textshare]# ll
total 0
drwxrwxrwx. 2 share2 share 28 Dec 21 01:32 share

⑥ 修改context值 放行防火墙

[root@localhost textshare]# chcon -t samba_share_t /textshare/share/ -R
[root@localhost textshare]# firewall-cmd --permanent --add-service=samba
success
[root@localhost textshare]# firewall-cmd --reload  						#重新加载防火墙
success
[root@localhost textshare]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens160
  sources: 
  services: cockpit dhcpv6-client samba ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
[root@localhost textshare]# systemctl restart smb nmb --now       	     #重启服务

二、linux测试连接

①安装samba服务端 和支持文件共享服务的软件包(cifs-utils)

  yum install samba-client -y
  yum install cifs-utils.x86_64 -y

②使用smbclient 访问服务器

Ⅰ、测试

在这里插入图片描述

Ⅱ、连接

[root@localhost ~]# smbclient //192.168.98.128/share -U share2%111111
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Mon Dec 21 03:04:30 2020
  ..                                  D        0  Mon Dec 21 01:58:02 2020
  text_share.tar                      N        0  Mon Dec 21 01:32:51 2020
  nmb.txt                             N        0  Mon Dec 21 01:58:12 2020
  123.txt                             A        0  Mon Dec 21 03:04:28 2020

		17811456 blocks of size 1024. 13365092 blocks available
smb: \> mkdir testdir					## 新建目录测试
smb: \> ls								## 新建成功
  .                                   D        0  Mon Dec 21 03:26:46 2020
  ..                                  D        0  Mon Dec 21 01:58:02 2020
  text_share.tar                      N        0  Mon Dec 21 01:32:51 2020
  nmb.txt                             N        0  Mon Dec 21 01:58:12 2020
  123.txt                             A        0  Mon Dec 21 03:04:28 2020
  testdir                             D        0  Mon Dec 21 03:26:46 2020

		17811456 blocks of size 1024. 13365092 blocks available
smb: \> exit

③ Linux端 挂载共享目录

[root@localhost ~]# mkdir -p /mnt/smb_share
[root@localhost ~]# mount -t cifs //192.168.98.128/share /mnt/smb_share/ -o username=share1
Password for share1@//192.168.98.128/share:  ******
[root@localhost ~]# df -h
Filesystem              Size  Used Avail Use% Mounted on
devtmpfs                952M     0  952M   0% /dev
tmpfs                   981M     0  981M   0% /dev/shm
tmpfs                   981M   18M  963M   2% /run
tmpfs                   981M     0  981M   0% /sys/fs/cgroup
/dev/mapper/rhel-root    17G  4.3G   13G  26% /
/dev/sda1              1014M  210M  805M  21% /boot
tmpfs                   196M  1.2M  195M   1% /run/user/42
tmpfs                   196M  4.6M  192M   3% /run/user/0
//192.168.98.128/share   17G  4.3G   13G  25% /mnt/smb_share

标签:Samba,share,textshare,samba,实例,服务器,root,smb,localhost
来源: https://blog.csdn.net/qq_52993001/article/details/120474436

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有