搭建Samba服务器笔记全套
生活随笔
收集整理的這篇文章主要介紹了
搭建Samba服务器笔记全套
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Top
- 安裝
- 端口與服務管理
- 其他常用命令
-
配置
- 全局配置
- 共享庫配置
- 用戶名密碼認證庫配置
- Samba 登錄用戶配置
-
防火墻配置
- 設定安全的上下文關系
- 本地系統設置訪問讀寫權限
- Pdbedit 用法
- Smbpasswd 用法
- 其他
-
Windows 下相關轉發
- 查看網絡連接 -- 可刪除緩存,用于切換登錄用戶
- Windows 設置 Smb 端口轉發
-
訪問 Samba 服務器
- 服務器 --- Linux
- 服務器 --- Windows
- Apple --- Mac
- Linux 掛載 samba 地址
- 參考網址
- 自動化配置腳本
安裝
# 安裝samba服務器
yum install -y samba
# samba 服務器地址
smb://user@192.168.0.10
# 查看安裝包
rpm -qa |grep samba
端口與服務管理
# 啟動samba進程
systemctl start smb
# 查看運行狀態
systemctl status smb
# 查看端口
netstat -antulp |grep smb
# 設置開機自啟動
systemctl enable smb
chkconfig smb on
# samba的主要配置文件
/etc/samba/smb.conf
# Samba服務使用的端口和協議:
1 端口137 (UDP) - NetBIOS名稱服務; 美國全國廣播公司
2 端口138 (UDP) - NetBIOS數據報服務
3 端口139 (TCP) - 共享文件和打印;它基于smbd(SMB) servermessageblock協議,主要用于局域網,文件共享協議) 。
4 端口389 (TCP) - LDAP (活動目錄模式)
5 端口445 (TCP) - NetBIOS服務在windos 2000或更高版本上使用此端口。 (CIFS、公共互聯網文件系統,它將SMB協議擴展到internet,然后實現internet文件共享。
6 端口901 (TCP) SWAT,用于web管理Samba
windows系統之間的文件共享協議: netbiosextenduserinterface (netbeui )協議和IPX/SPX協議
NetBEUI協議是一種短而精悍、通信效率高的廣播型協議,安裝后無需設置,特別適用于“網絡鄰居”中的數據傳輸。
其他常用命令
# 查看 samba 服務狀態及其客戶端訪問情況
smbstatus
/usr/bin/smbclient # 客戶端功能
點我回頂部
配置
全局配置
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
config file = /etc/samba/%U.smb.conf # 使得不同的登錄用戶只加載其自身的配置,%U 代表用戶名
printing = cups
printcap name = cups
load printers = yes
cups options = raw
interfaces = ens9f3 192.168.0.200/24 # 訪問接口 和 IP
hosts allow = 192.168.0. # 客戶端 白名單
log file = /var/log/samba/log.%m # 日志文件配置
max log size = 50000
smb ports = 1234 # 自定義服務端口
#
#[homes]
# comment = Home Directories
# valid users = %S, %D%w%S
# browseable = No
# read only = No
# inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
共享庫配置
[d200_temp]
comment = please do not modify it all will
path= /data/shared/d200_d
writable = yes
public = yes
點我回頂部
用戶名密碼認證庫配置
[d200_temp]
comment = please do not modify it all will
path= /data/shared/d200_d
public = no
valid users = sit,@ydd
printable = no
write list = sit,@ydd
Samba 登錄用戶配置
sit_home_Dir="/raid/shared/d200_d/temp"
sit_pwd="h3c@123"
userdel -r sit &> /dev/null
groupdel ydd &> /dev/null
groupadd ydd
useradd sit -d /raid/shared/d200_d/temp -s /sbin/nologin -p ${sit_pwd}
pdbedit -x sit
echo "sit pwd : ${sit_pwd}"
pdbedit -a -u sit
usermod -a -G ydd sit
# 添加用戶
smbpasswd -a <用戶名>
# 或
pdbedit -a -u <用戶名>
# 重置密碼
smbpasswd <用戶名>
# 刪除用戶
pdbedit -x <用戶名>
點我回頂部
防火墻配置
# 開啟防火墻
systemctl start firewalld.service
# 放行 samba
firewall-cmd --add-service samba --permanent
firewall-cmd --reload # 重新加載防火墻配置
firewall-cmd --list-all | grep samba -q # 查詢防火墻信息
# iptables 規則配置
iptables -I RH-Firewall-1-INPUT 5 -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
iptables -I RH-Firewall-1-INPUT 5 -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
iptables -I RH-Firewall-1-INPUT 5 -p udp -m udp --dport 137 -j ACCEPT
iptables -I RH-Firewall-1-INPUT 5 -p udp -m udp --dport 138-j ACCEPT
iptables-save
service iptables restart
設定安全的上下文關系
# 將 samba 目錄共享給其他用戶,
chcon -t samba_share_t <共享目錄> # 修改對象的安全上下文
# 第二種方法,
semanage fcontext -a -t samba_share_t <共享目錄>
restorecon -FRv /home/kevin # 刷新上下文,使其立即生效
#如果samba服務器共享目錄給多個域,則需要:
setsebool -P allow_smbd_anon_write=1
//If you are setting up this machine as a Samba server and wish to share the home directories
samba服務器要共享家目錄時:
setsebool -P samba_enable_home_dirs 1
//If you want to use a remote Samba server for the home directories on this machine
如果你需在本機上使用遠程samba服務器的家目錄
setsebool -P use_samba_home_dirs 1
//You can disable SELinux protection for the samba daemon by executing
setsebool -P samba_domain_controller 1
# 可讀可寫
setsebool -P samba_export_all_rw 1
# 只讀
setsebool -P samba_export_all_ro 1
# 關閉selinux關于samba的進程守護的保護
setsebool -P smbd_disable_trans 1 # 0是關閉 1是開啟
# 查詢SElinux策略內各項 samba 規則的布爾值
[root@localhost ~]# getsebool -a | grep smb
smbd_anon_write --> off
[root@localhost ~]# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_load_libgfapi --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
tmpreaper_use_samba --> off
use_samba_home_dirs --> off
virt_use_samba --> off
點我回頂部
本地系統設置訪問讀寫權限
# 設置文件訪問權限
setfacl -R -m g:sit:rwx <目錄> # 設置用戶組權限
setfacl -R -m u:sit:rwx <目錄> # 設置用戶權限
# 獲取文件權限信息
getfacl <文件>
Pdbedit 用法
# 命令用于管理Samba服務的帳戶信息數據庫
pdbedit -a username # 新建Samba賬戶
pdbedit -x username # 刪除Samba賬戶
pdbedit -r -u user # 修改samba用戶信息
pdbedit -L # 列出Samba用戶列表,讀取passdb.tdb數據庫文件。
pdbedit -Lv # 列出Samba用戶列表詳細信息。
pdbedit -c “[D]” -u username # 暫停該Samba用戶賬號。
pdbedit -c “[]” -u username # 恢復該Samba用戶賬號。
Smbpasswd 用法
smbpasswd -a user # 添加一個samba用戶
smbpasswd -d user # 禁用一個samba用戶
smbpasswd -e user # 恢復一個samba用戶
smbpasswd -x user # 刪除一個samba用戶
點我回頂部
其他
# 重新加載配置
smbcontrol all reload-config
# 允許用戶執行共享上的所有文件,
acl allow execute always = yes
# 添加網絡映射到指定驅動器號
net use H: \\server\users\demo\ /persistent:yes
# 用戶管理
https://wiki.samba.org/index.php/User_and_Group_management
Windows 下相關轉發
查看網絡連接 -- 可刪除緩存,用于切換登錄用戶
# 顯示當前網絡連接列表
net use
# 刪除一個網絡連接配置
net use 遠程連接名稱 /del
# 一次性全部刪除
net use * /del
# 若以上方法不管用,可進入控制臺刪除網絡憑證
Windows 設置 Smb 端口轉發
# 使用管理員權限
# 查看端口轉發
netsh interface portproxy show all
# 配置端口轉發
netsh interface portproxy add v4tov4 listenport=445 listenaddress=127.0.0.1 connectport=samba服務器地址 connectaddress=samba端口
# 清除所有端口轉發規則
netsh interface portproxy reset
點我回頂部
訪問 Samba 服務器
服務器 --- Linux
1、安裝samba client
sudo apt-get install smbclient
yum install samba-client
2、獲取指定 Samba 服務器的共享列表
smbclient -L 192.168.1.1 -U <username>
smbclient -L 192.168.1.1 -U <username> --workgroup=SAMBA
3、連接共享目錄 -- 交互式
smbclient 192.168.1.1/<共享目錄名> -U username
4、連接共享目錄 --- 一次性連接共享目錄進行指定操作后退出
smbclient -U sit -c 'ls' //172.16.89.129/<共享目錄名>
服務器 --- Windows
# 1、快捷鍵 `Win + E` 打開文件資源管理器
# 2、在地址欄中輸入 `\\<Samba 服務器地址>`
若需要驗證則再輸入用戶名和密碼登錄
Apple --- Mac
# 1、打開訪達
# 2、快捷鍵 `Cmd + K` 連接文件服務器
輸入samba 服務器 IP ,
若需要驗證則再輸入用戶名和密碼登錄
mac如何訪問windows共享文件夾--- samba 服務器
點我回頂部Linux 掛載 samba 地址
# 1、安裝
apt install cifs-utils
# or
yum install cifs-utils
# 2、在本地創建一個掛載點目錄
sudo mkdir /home/user/shareFiles
# 3、掛載
sudo mount -t cifs -o username=xxx,password=xxx //<目標IP地址或主機名>/<共享目錄名> <掛載點目錄>
mount -t cifs //192.168.1.65/linuxsamba /database -o username=smbuser,password=123456,rw,file_mode=0777,dir_mode=0777,setuid=509,setgid=101
# 或者
mount -t cifs //192.168.1.65/linuxsamba /database -o username=smbuser,password=123456,rw
參考網址
Linux下安裝部署Samba共享盤的操作手冊
騰訊云---Linux/centos上如何配置管理samba服務器
Linux/centos上如何配置管理samba服務器?
Samba服務器的配置與管理
samba客戶端的使用與服務端的搭建
Linux系統工程師3.5網絡文件系統
smb協議詳解和samba服務的配置
使用POSIX ACL設置共享
將Samba設置為獨立服務器
smb.conf--- man手冊
Samba命令幫助文檔
幫助文檔-----002
點我回頂部自動化配置腳本
#
總結
以上是生活随笔為你收集整理的搭建Samba服务器笔记全套的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为了性能,慎用递归
- 下一篇: 微服务系列-基于Spring Cloud