当前位置: 首页 > news >正文

linux文件共享之samba

1.介绍

        Samba是一个开源文件共享服务,可以使linux与windows之间进行文件共享,可以根据不同人员调整共享设置以及权限管理。

2.安装

        一个命令就OK了:yum install -y samba

[root@ansible01 ~]# yum install -y samba
已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager
epel                                                                                                                                                                | 4.3 kB  00:00:00     
rhel-7-server-rpms                                                                                                                                                  | 3.5 kB  00:00:00     
(1/2): epel/x86_64/updateinfo                                                                                                                                       | 1.0 MB  00:00:02     
(2/2): epel/x86_64/primary_db                                                                                                                                       | 8.7 MB  00:00:26     
正在解决依赖关系
--> 正在检查事务
---> 软件包 samba.x86_64.0.4.10.16-25.el7_9 将被 安装
--> 正在处理依赖关系 libwbclient = 4.10.16-25.el7_9,它被软件包 samba-4.10.16-25.el7_9.x86_64 需要
--> 正在处理依赖关系 libwbclient = 4.10.16-25.el7_9,它被软件包 samba-4.10.16-25.el7_9.x86_64 需要
......
作为依赖被升级:libldb.x86_64 0:1.5.4-2.el7_9               libsmbclient.x86_64 0:4.10.16-25.el7_9           libwbclient.x86_64 0:4.10.16-25.el7_9      samba-client-libs.x86_64 0:4.10.16-25.el7_9     samba-common.noarch 0:4.10.16-25.el7_9      samba-common-libs.x86_64 0:4.10.16-25.el7_9     完毕!
[root@ansible01 ~]# 

3.配置

        我们的目的是创建3个用户:test1、test2、test3,三个共享文件夹:share1、share2、share3,权限为:

        share1目录三个用户都可读可写

        share2目录是三个用户都可读,但是仅test2可写

        share3目录是仅test3可读可写

        3.1 创建用户和目录

#1.创建3个用户test1,test2,test3,并禁止登录
[root@ansible01 ~]# for i in {test1,test2,test3};do useradd $i -s /sbin/nologin;done
#2.检查是否创建成功
[root@ansible01 ~]# cat /etc/passwd|grep test
test1:x:1001:1001::/home/test1:/sbin/nologin
test2:x:1002:1002::/home/test2:/sbin/nologin
test3:x:1003:1003::/home/test3:/sbin/nologin
#3.设置SMB用户认证密码
[root@ansible01 ~]# smbpasswd -a test1
New SMB password:
Retype new SMB password:
Added user test1.
[root@ansible01 ~]# smbpasswd -a test2
New SMB password:
Retype new SMB password:
Added user test2.
[root@ansible01 ~]# smbpasswd -a test3
New SMB password:
Retype new SMB password:
Added user test3.
#4.创建3个共享目录
[root@ansible01 ~]# mkdir /share{1..3}
#5.创建测试文件
[root@ansible01 ~]# touch /share1/file{11..19}
[root@ansible01 ~]# touch /share2/file{21..29}
[root@ansible01 ~]# touch /share3/file{31..39}
#6.设置共享文件权限
[root@ansible01 ~]# chmod o+w /share{1..3}

3.2 修改配置文件

[root@ansible01 ~]# cat /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 = SAMBAsecurity = userpassdb backend = tdbsamprinting = cupsprintcap name = cupsload printers = yescups options = raw
[share1]
comment = this is share1
path = /share1
public = no
browseable = yes
writable = yes
[share2]
comment = this is share2
path = /share2
public = no
browseable = yes
writable = no
write list = test2
[share3]
comment = this is share3
path = /share3
public = no
browseable = yes
writable = no
write list = test3
valid users = test3

path:共享目录绝对路径

public:是否允许匿名访问,yes代表允许,no代表不允许

browseable:当前状态下的共享文件是否公开可见,为no时,A用户登录后无法看到file文件夹,为yes时用户登录可以看到文件夹

writable:登录用户能否读写,yes是可读写,no是仅读

write list:可写用户,一般是writable为no时添加

valid users:指定用户访问

3.3 服务启动

[root@ansible01 ~]# systemctl restart smb
[root@ansible01 ~]# systemctl status smb.service 
● smb.service - Samba SMB DaemonLoaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled)Active: active (running) since 三 2024-05-29 10:20:05 CST; 5s agoDocs: man:smbd(8)man:samba(7)man:smb.conf(5)Main PID: 16809 (smbd)Status: "smbd: ready to serve connections..."Tasks: 4CGroup: /system.slice/smb.service├─16809 /usr/sbin/smbd --foreground --no-process-group├─16811 /usr/sbin/smbd --foreground --no-process-group├─16812 /usr/sbin/smbd --foreground --no-process-group└─16813 /usr/sbin/smbd --foreground --no-process-group5月 29 10:20:05 ansible01 systemd[1]: Starting Samba SMB Daemon...
5月 29 10:20:05 ansible01 smbd[16809]: [2024/05/29 10:20:05.830974,  0] ../../lib/util/become_daemon.c:136(daemon_ready)
5月 29 10:20:05 ansible01 smbd[16809]:   daemon_ready: daemon 'smbd' finished starting up and ready to serve connections
5月 29 10:20:05 ansible01 systemd[1]: Started Samba SMB Daemon.

4.测试

        4.1 linux测试

#1.安装samba客户端
[root@k8s-master ~]# yum install samba-client cifs-utils -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
base                                                                                                                                                                | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                                                    | 3.5 kB  00:00:00     
epel                                                                                                                                                                | 4.3 kB  00:00:00     
extras                                                                                                                                                              | 2.9 kB  00:00:00     
kubernetes                                                                                                                                                          | 1.4 kB  00:00:00     
updates                                                                                                                                                             | 2.9 kB  00:00:00     
Package samba-client-4.10.16-25.el7_9.x86_64 already installed and latest version
Package cifs-utils-6.2-10.el7.x86_64 already installed and latest version
Nothing to do
#2.查看服务器共享目录状态
[root@k8s-master ~]# smbclient -L \\11.0.1.18 -U test1
Enter SAMBA\test1's password: Sharename       Type      Comment---------       ----      -------share1          Disk      this is share1share2          Disk      this is share2share3          Disk      this is share3IPC$            IPC       IPC Service (Samba 4.10.16)
Reconnecting with SMB1 for workgroup listing.Server               Comment---------            -------Workgroup            Master---------            -------
[root@k8s-master ~]# smbclient -L \\11.0.1.18 -U test2
Enter SAMBA\test2's password: Sharename       Type      Comment---------       ----      -------share1          Disk      this is share1share2          Disk      this is share2share3          Disk      this is share3IPC$            IPC       IPC Service (Samba 4.10.16)
Reconnecting with SMB1 for workgroup listing.Server               Comment---------            -------Workgroup            Master---------            -------
[root@k8s-master ~]# smbclient -L \\11.0.1.18 -U test3
Enter SAMBA\test3's password: Sharename       Type      Comment---------       ----      -------share1          Disk      this is share1share2          Disk      this is share2share3          Disk      this is share3IPC$            IPC       IPC Service (Samba 4.10.16)
Reconnecting with SMB1 for workgroup listing.Server               Comment---------            -------Workgroup            Master---------            -------

        我们分别挂载后在测试下:

mount -t cifs -o username=test1,password=123456 "\\\11.0.1.18\share1" /mnt

#1.test1对share1目录的权限
[root@k8s-master ~]# mount -t cifs -o username=test1,password=123456 "\\\11.0.1.18\share1" /mnt
[root@k8s-master ~]# cd /mnt/
[root@k8s-master mnt]# ls
file11  file12  file13  file14  file15  file16  file17  file18  file19
[root@k8s-master mnt]# ls -la
total 0
drwxr-xr-x   2 root root   0 May 29 10:06 .
dr-xr-xr-x. 18 root root 256 May 27 13:43 ..
-rwxr-xr-x   1 root root   0 May 29 10:06 file11
-rwxr-xr-x   1 root root   0 May 29 10:06 file12
-rwxr-xr-x   1 root root   0 May 29 10:06 file13
-rwxr-xr-x   1 root root   0 May 29 10:06 file14
-rwxr-xr-x   1 root root   0 May 29 10:06 file15
-rwxr-xr-x   1 root root   0 May 29 10:06 file16
-rwxr-xr-x   1 root root   0 May 29 10:06 file17
-rwxr-xr-x   1 root root   0 May 29 10:06 file18
-rwxr-xr-x   1 root root   0 May 29 10:06 file19
[root@k8s-master mnt]# echo "hello world" >file12
#2.test1对share2目录的权限
[root@k8s-master /]# mount -t cifs -o username=test1,password=123456 "\\\11.0.1.18\share2" /mnt
[root@k8s-master /]# cd /mnt/
[root@k8s-master mnt]# ls
file21  file22  file23  file24  file25  file26  file27  file28  file29
[root@k8s-master mnt]# ls -la
total 0
drwxr-xr-x   2 root root   0 May 29 10:06 .
dr-xr-xr-x. 18 root root 256 May 27 13:43 ..
-rwxr-xr-x   1 root root   0 May 29 10:06 file21
-rwxr-xr-x   1 root root   0 May 29 10:06 file22
-rwxr-xr-x   1 root root   0 May 29 10:06 file23
-rwxr-xr-x   1 root root   0 May 29 10:06 file24
-rwxr-xr-x   1 root root   0 May 29 10:06 file25
-rwxr-xr-x   1 root root   0 May 29 10:06 file26
-rwxr-xr-x   1 root root   0 May 29 10:06 file27
-rwxr-xr-x   1 root root   0 May 29 10:06 file28
-rwxr-xr-x   1 root root   0 May 29 10:06 file29
[root@k8s-master mnt]# vim file21
[root@k8s-master mnt]# echo "hello world" >file21
-bash: file21: Permission denied
#3.test1对share3目录的权限
[root@k8s-master ~]# mount -t cifs -o username=test1,password=123456 "\\\11.0.1.18\share3" /mnt
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

我们只使用test1对share1、share2、share3进行了测试。

        4.2 windows测试

        我们直接在我的电脑中舒服\\11.0.1.18回车输入smb账号密码后即可

可以分别进去后看能否读写即可

注:

使用Windows客户端测试,每测试完一个用户需要在命令行中运行下面命令,删除缓存。

net use * /del

修改smb默认端口:

vim /etc/samba/smb.conf#在[global]下添加
smb ports = 555

相关文章:

linux文件共享之samba

1.介绍 Samba是一个开源文件共享服务,可以使linux与windows之间进行文件共享,可以根据不同人员调整共享设置以及权限管理。 2.安装 一个命令就OK了:yum install -y samba [rootansible01 ~]# yum install -y samba 已加载插件:l…...

端午传统食品创意营销方案

端午传统食品创意营销方案 目 录 一、市场营销环境分析 1 (一)历史记载 1 (二)粽叶的象征 1 (三)粽子文化 1 (四)竞争分析 2 (五)粽子当今发展 4 二、产品创…...

制作ChatPDF之Elasticsearch8.13.4搭建(一)

Elasticsearch8.x搭建 在Windows系统上本地安装Elasticsearch的详细步骤如下: 1. 下载Elasticsearch 访问 Elasticsearch下载页面。选择适用于Windows的版本8.13.4,并下载ZIP文件。 2. 解压文件 下载完成后,找到ZIP文件(例如…...

一种最大重叠离散小波包特征提取和支持向量机的ECG心电信号分类方法(MATLAB 2018)

目前小波分析算法常采用Mallat快速算法。该算法由与滤波器卷积、隔点采样和隔点插零等三个环节组成。由于实际使用的滤波器并不具有理想频域特性,使得在标准二进小波算法中存在着频率混叠和小波系数失真等缺点,在标准二进小波包算法中还存在频带错乱现象…...

德勤:中国、印度等对ChatGPT等生成式AI应用,处领先地位

全球四大会计事务所之一的德勤(Deloitte)在官网发布了一份,名为《Generative AI in Asia Pacific: Young employees lead as employers play catch-up》的深度调查报告。 主要查看中国、澳大利亚、印度、日本、新加坡、韩国、中国台湾等亚太…...

开发靠谱心得

1、目的 记录下 不靠谱的行为,以规范自己的开发步骤。 2、内容 2.1 不应该做哪些事情 1、禁止虚假的交付 2、禁止随意的承诺 3、禁止推卸责任式的通知 4、禁止组织浪费多人时间的会议 5、禁止重要事故不向上反馈 6、禁止延期不提前预警 7、禁止遗漏工作和疏忽大意 …...

【OpenHarmony】TypeScript 语法 ④ ( 函数 | TypeScript 具名函数和匿名函数 | 可选参数 | 剩余参数 | 箭头参数 )

文章目录 一、TypeScript 函数1、TypeScript 具名函数和匿名函数2、TypeScript 函数 与 JavaScript 函数对比3、TypeScript 函数 可选参数4、TypeScript 函数 剩余参数5、TypeScript 箭头函数 参考文档 : <HarmonyOS第一课>ArkTS开发语言介绍 一、TypeScript 函数 1、Typ…...

嵌入式工程师人生提质的十大成长型思维分享

大家好,作为一名嵌入式开发者,很多时候,需要考虑个人未来的发展,人生旅途复杂多变,时常面临各种各样的挑战。如何在这个复杂多变的社会中稳步向前,不断成长,成为每个人都应该思考的问题。实际上,思维方式的差异决定我们应对挑战的能力与成长的速度。 第一:寻找自我坐…...

名下企业查询,清晰明了;在线操作,方便快捷

在现代社会&#xff0c;越来越多的人开始涉足创业和投资&#xff0c;拥有自己的企业成为一种时尚。然而&#xff0c;随之而来的是繁琐的企业注册流程和复杂的信息查询。为了解决这个问题&#xff0c;挖数据平台推出了一项名下企业查询接口&#xff0c;提供了一种方便快捷的方式…...

图书推荐:ChatGPT专业知识信息课程

《ChatGPT专业知识信息课程》&#xff08;ChatGPT-Expertise Informative Course&#xff09; 是一本由Dwayne Anderson撰写的电子书&#xff0c;提供了关于ChatGPT的丰富知识。该书涵盖了与ChatGPT相关的各种主题&#xff0c;如其与OpenAI的关系、ChatGPT与GPT-3之间的混淆、C…...

Java项目:94 springboot大学城水电管理系统

作者主页&#xff1a;源码空间codegym 简介&#xff1a;Java领域优质创作者、Java项目、学习资料、技术互助 文中获取源码 项目介绍 本管理系统有管理员和用户。 本大学城水电管理系统管理员功能有个人中心&#xff0c;用户管理&#xff0c;领用设备管理&#xff0c;消耗设备…...

Unity内制作动画

Unity内制作动画 动画剪辑&#xff08;Animation Clips&#xff09; 创建动画剪辑&#xff1a;在Unity中&#xff0c;可以通过导入动画数据来创建动画剪辑。这些数据可以是FBX、OBJ等格式的3D模型文件&#xff0c;其中包含关键帧动画。 编辑动画剪辑&#xff1a;在Unity的Anim…...

Java中的JDBC如何连接数据库并执行操作

JDBC&#xff08;Java Database Connectivity&#xff09;是Java编程语言中用来连接和操作数据库的一组API。以下是一个基本的步骤指南&#xff0c;用于连接数据库并执行操作&#xff1a; 导入JDBC驱动 首先&#xff0c;你需要将数据库的JDBC驱动添加到你的项目依赖中。如果你…...

webserver服务器从零搭建到上线(六)|Timestamp类和InetAddress类

本节我们重点来谈论&#xff1a; 时间类和我们的初始化链接地址类 文章目录 Timestamp类成员函数实现 InetAddress类具体实现 Timestamp类 我们为什么要封装一个时间类呢&#xff1f; 这也是一个大型项目必须的基础组建&#xff0c;这样我们不仅可以提高代码的可读性&#xf…...

【Java】一文看懂Thread 线程池的 7 种创建方式、任务队列及自定义线程池(代码示例)

本文摘要&#xff1a;【Java】Thread 线程池的 7 种创建方式及自定义线程池&#xff08;代码示例版&#xff09; &#x1f60e; 作者介绍&#xff1a;我是程序员洲洲&#xff0c;一个热爱写作的非著名程序员。CSDN全栈优质领域创作者、华为云博客社区云享专家、阿里云博客社区专…...

【SpringBoot】四种读取 Spring Boot 项目中 jar 包中的 resources 目录下的文件

本文摘要&#xff1a;四种读取 Spring Boot 项目中 jar 包中的 resources 目录下的文件 &#x1f60e; 作者介绍&#xff1a;我是程序员洲洲&#xff0c;一个热爱写作的非著名程序员。CSDN全栈优质领域创作者、华为云博客社区云享专家、阿里云博客社区专家博主。公粽号&#xf…...

掌控未来,爱普生SR3225SAA用于汽车钥匙、射频电路的智慧引擎

为了响应市场需求&#xff0c;Epson使用独家QMEMS*2技术所生产的石英振荡器&#xff0c;与其精巧的半导体技术所制造的射频传输器电路&#xff0c;开发了SR3225SAA。不仅内建的石英震荡器之频率误差仅有2 ppm&#xff0c;更使其封装尺寸达仅3.2 mm x 2.5 mm&#xff0c;为客户大…...

第五届武汉纺织大学ACM程序设计竞赛 个人题解(待补完)

前言&#xff1a; 上周周日教练要求打的一场重现赛&#xff0c;时长五个小时&#xff0c;题目难度还行&#xff0c;除了部分题目前我还写不出来之外&#xff0c;大部分题都写完或补完了&#xff0c;这边给出比赛链接和我的代码&#xff08;有些是队友的&#xff09;和题解。 正…...

LeetCode---哈希表

242. 有效的字母异位词 给定两个字符串 s 和 t &#xff0c;编写一个函数来判断 t 是否是 s 的字母异位词。 注意&#xff1a;若 s 和 t 中每个字符出现的次数都相同&#xff0c;则称 s 和 t 互为字母异位词。 代码示例&#xff1a; //时间复杂度: O(n) //空间复杂度: O(1) c…...

Python知识点13---面向对象的编程

提前说一点&#xff1a;如果你是专注于Python开发&#xff0c;那么本系列知识点只是带你入个门再详细的开发点就要去看其他资料了&#xff0c;而如果你和作者一样只是操作其他技术的Python API那就足够了。 Python是一个完全面向对象开发的语言&#xff0c;它的一切都以对象的…...

告别人工筛选!用Word2vec构建主题词库,我们拿“网络暴力”关键词试了试

智能主题词库构建实战&#xff1a;用Word2vec挖掘语义关联词汇 在信息爆炸的时代&#xff0c;内容运营和产品经理们常常面临一个共同挑战&#xff1a;如何从海量文本中快速识别和归类相关主题内容。传统的人工筛选方法不仅效率低下&#xff0c;还容易遗漏那些变体表达和新兴网络…...

避坑指南:深度相机与RGB相机标定中的5个常见错误

避坑指南&#xff1a;深度相机与RGB相机标定中的5个常见错误 在三维重建和增强现实开发中&#xff0c;深度相机与RGB相机的联合标定是基础却极易出错的关键环节。许多开发者投入大量时间调试标定结果&#xff0c;却因忽视了一些看似简单的细节而功亏一篑。本文将揭示五个最常被…...

保姆级教程:手把手教你用Zabbix监控MySQL数据库(Percona模板实战)

深度实战&#xff1a;基于Percona模板构建企业级MySQL监控体系 当数据库规模突破百万级QPS时&#xff0c;传统的手动检查方式就像用体温计测量森林大火——既低效又危险。去年某电商大促期间&#xff0c;我们曾因未及时发现连接数耗尽导致核心交易库雪崩&#xff0c;这个教训让…...

终极CPU稳定性测试指南:CoreCycler单核心轮询测试完全教程

终极CPU稳定性测试指南&#xff1a;CoreCycler单核心轮询测试完全教程 【免费下载链接】corecycler Script to test single core stability, e.g. for PBO & Curve Optimizer on AMD Ryzen or overclocking/undervolting on Intel processors 项目地址: https://gitcode.…...

Phi-4-mini-reasoning应用场景:数学建模竞赛辅助推导与公式生成

Phi-4-mini-reasoning应用场景&#xff1a;数学建模竞赛辅助推导与公式生成 1. 模型概述与核心能力 Phi-4-mini-reasoning是一款由微软开发的轻量级开源模型&#xff0c;专为数学推理、逻辑推导和多步解题等强逻辑任务设计。这个3.8B参数的模型虽然体积小巧&#xff0c;但在数…...

3大创新突破:CoreCycler单核心稳定性测试全攻略

3大创新突破&#xff1a;CoreCycler单核心稳定性测试全攻略 【免费下载链接】corecycler Script to test single core stability, e.g. for PBO & Curve Optimizer on AMD Ryzen or overclocking/undervolting on Intel processors 项目地址: https://gitcode.com/gh_mir…...

Labelme标注实战:5分钟搞定语义分割数据集制作(附避坑指南)

Labelme标注实战&#xff1a;5分钟搞定语义分割数据集制作&#xff08;附避坑指南&#xff09; 当你第一次接触计算机视觉项目时&#xff0c;可能会被海量的标注需求吓到。别担心&#xff0c;今天我要分享的是如何用Labelme这个轻量级工具&#xff0c;快速完成语义分割数据标注…...

Unpaywall扩展:一键解锁学术论文的终极免费方案

Unpaywall扩展&#xff1a;一键解锁学术论文的终极免费方案 【免费下载链接】unpaywall-extension Firefox/Chrome extension that gives you a link to a free PDF when you view scholarly articles 项目地址: https://gitcode.com/gh_mirrors/un/unpaywall-extension …...

Kook Zimage 真实幻想 Turbo在软件测试中的应用:自动化UI设计验证

Kook Zimage 真实幻想 Turbo在软件测试中的应用&#xff1a;自动化UI设计验证 1. 引言&#xff1a;UI设计验证的痛点与机遇 在软件开发流程中&#xff0c;UI设计验证一直是个让人头疼的环节。测试人员需要对照设计稿&#xff0c;逐个像素检查界面元素的位置、颜色、字体和布局…...

AI赋能软件测试:基于PyTorch视觉模型实现自动化GUI测试脚本生成效果演示

AI赋能软件测试&#xff1a;基于PyTorch视觉模型实现自动化GUI测试脚本生成效果演示 1. 效果亮点预览 想象一下这样的场景&#xff1a;一个AI系统正在自动测试你的软件界面&#xff0c;它能像人类测试工程师一样"看"懂屏幕上的每个元素&#xff0c;发现那些传统脚本…...