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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/21071.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/21071.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/21071.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Python爬蟲之簡單學習BeautifulSoup庫,學習獲取的對象常用方法,實戰豆瓣Top250

BeautifulSoup是一個非常流行的Python庫,廣泛應用于網絡爬蟲開發中,用于解析HTML和XML文檔,以便于從中提取所需數據。它是進行網頁內容抓取和數據挖掘的強大工具。 功能特性 易于使用: 提供簡潔的API,使得即使是對網頁結構不熟悉…

【一刷《劍指Offer》】面試題 31:連續子數組的最大和

牛客對應題目鏈接:連續子數組最大和_牛客題霸_牛客網 (nowcoder.com) 力扣對應題目鏈接:53. 最大子數組和 - 力扣(LeetCode) 核心考點 :簡單動歸問題。 一、《劍指Offer》對應內容 二、分析題目 1、貪心 從前往后迭…

backbone主干網絡的選取

backbone_name 通常用于指定深度學習模型的主干網絡(backbone network)。主干網絡是指在整個模型中承擔主要特征提取任務的部分。不同的主干網絡有不同的架構和特征提取能力,適用于不同的任務和數據集。 針對戴著口罩和戴著3D眼睛提取人臉特征…

關于Posix標準接口和Nuttx操作系統

基本介紹 主要參考: Linux 系統中的 POSIX 接口詳細介紹_linux posix-CSDN博客 POSIX(Portable Operating System Interface,可移植操作系統接口)是由 IEEE(Institute of Electrical and Electronics Engineers&#x…

大模型對齊方法筆記四:針對領域問答來進行知識對齊方法KnowPAT

KnowPAT KnowPAT(Knowledgeable Preference AlignmenT) 出自2023年11月的論文《Knowledgeable Preference Alignment for LLMs in Domain-specific Question Answering》,主要針對領域問答來進行知識對齊。 在領域問答有兩個挑戰:希望輸出滿足用戶的要…

Notepad++ 常用

File Edit search view Encoding Language Settings Tools Macro Run Plugins Window 文件 編輯 搜索 視圖 編碼 語言 設置 工具 宏 運行 插件 窗口 快捷方式 定位行 :CTRL g查找: CTRL F替換&am…

小白也能看得懂的基于HTML+CSS+JS實現的五子棋小游戲

五子棋是一種起源于中國的傳統棋類游戲,具有悠久的歷史。 基本規則 棋盤: 五子棋通常在一個 15x15 的棋盤上進行,但也可以在更大的棋盤上進行。棋盤上的每個交叉點稱為一個“點”。 棋子: 五子棋使用黑白兩色的棋子。兩名玩家分別…

【競技寶】歐冠:多特搶開局失敗,皇馬展示頂級防守反擊

本賽季歐冠決賽結束,皇馬在上半場被壓制的情況下,2比0擊敗多特蒙德奪得隊史第15座歐冠冠軍獎杯。比賽中多特蒙德已經展現出了不俗的狀態,可是面對老辣的皇馬他們還是敗下陣來,皇馬用頂級的防守反擊給多特上了一課。通過這場比賽,相信球迷們也清楚當今足壇硬實力不可或缺。 在許…

《Effective C++》《資源管理——14、在資源管理類中小心copying行為》

文章目錄 1、Terms14:Think carefully about copying behavior in resource-managing classes方法一:禁止復制方法二:對底層資源使出“引用計數法”方法三:復制底部資源方法四:轉移底部資源的擁有權 2、總結3、參考 1、Terms14:Th…

7-18 對象關系映射(orm_name)---PTA實驗C++

一、題目描述 一開始看到對象關系映射,其實我是拒絕的。這三個詞湊一塊,能是給C初學者的題嗎? 再仔細讀需求,才發現在課設項目已經用過這功能。Object Relational Mapping(ORM)就是面向對象(O…

計算機基礎之:LSM樹

使用過hbase、cassandra之類nosql數據庫的小伙伴對LSM樹結構應該有所耳聞,那么這種數據結構有哪些優劣勢呢,本文做下簡單介紹。 LSM(全稱:Log-Structured Merge Tree)是一種廣泛應用于現代數據庫和存儲系統的數據結構…

《平淵》· 柒 —— 大道至簡?真傳一句話,假傳萬卷書!

《平淵》 柒 "真傳一句話, 假傳萬卷書" 對于 "大道至簡",不少專家可能會說出一大堆亂七八糟的名詞, 比如這樣: 所謂 "大道" 即支撐天地運轉的 "系統自動力",更具體地來說,即是天地人以…

快手游戲《無盡夢回》官宣開測:熱血動作肉鴿來襲

易采游戲網最新消息:5月30日11:00,快手自研的夢境主題動作冒險手游《無盡夢回》正式宣布開啟測試。此次測試名為“肉鴿進化實驗”,旨在測試多角色技能交會的玩法。游戲將開放32人同局競技,讓玩家在激烈的戰斗中角逐出唯一的勝利者…

HTML如何讓文字底部線條不緊貼在文字下面(既在內容下方又超出內容區域)

hello,大家好,星途星途今天給大家帶來的內容是如何讓文字底部線條不緊貼在文字下面。 話不多說,先上效果圖 簡單來說就是padding和margin的區別。 在網頁設計中,有時我們想要給某個元素添加一個裝飾性的線條,比如底部…

過濾器、監聽器、攔截器的區別

過濾器、監聽器、攔截器的區別 過濾器(filter)、監聽器(Listener)是JavaWeb的三大組件。而攔截器(Interceptor)是Spring框架中的。 我們主要是要分清除過濾器和攔截器的區別: 實現原理&#…

overleaf 寫參考文獻引用

目錄 1、 新建.bib 文件 2、導入引用 3、在文檔中引用參考文獻 4、生成參考文獻列表 1、 新建.bib 文件 在Overleaf項目中,你可以選擇導入現有的 .bib 文件或在項目中創建一個新的 .bib 文件來管理你的參考文獻。 導入.bib 文件: 在項目文件樹中點擊…

11. RBAC權限管理從零到一實現(二)

前端頁面已提交至git https://github.com/SJshenjian/cloud-web默認用戶名密碼admin 1

MySql 數據類型選擇與優化

選擇優化的數據類型 更小的通常更好 一般情況下盡量使用可以正確存儲數據的最小類型。更小的數據類型通常更快,因為它們占用更少的磁盤,內存和CPU緩存,并且處理時需要的CPU周期也更少。但也要確保沒有低估需要存儲值的范圍。 簡單就好 簡單的…

【自然語言處理】【Scaling Law】Observational Scaling Laws:跨不同模型構建Scaling Law

相關博客 【自然語言處理】【Scaling Law】Observational Scaling Laws:跨不同模型構建Scaling Law 【自然語言處理】【Scaling Law】語言模型物理學 第3.3部分:知識容量Scaling Laws 【自然語言處理】Transformer中的一種線性特征 【自然語言處理】【大…

jmeter性能優化之tomcat配置與基礎調優

一、 修改tomcat初始和最大堆內存 進入到/usr/local/tomcat7-8083/bin目錄下,編輯catalina.sh文件,,默認堆內存是600m,初始堆內存和最大堆內存保持一致, 可以更改到本機內存的70%,對于Linux系統&#xff0…