CentOS9与Windows通过Samba实现永久共享配置

64 sudo dnf install samba samba-client samba-common-tools

65 sudo mkdir -p /srv/samba/shared

66 sudo chown -R nobody:nogroup /srv/samba/shared

67 sudo chown -R nobody:nobody /srv/samba/shared

68 sudo chmod -R 0775 /srv/samba/shared

69 sudo smbpasswd -a smart

70 vim /etc/samba/smb.conf

71 sudo systemctl restart smb nmb

72 sudo systemctl enable smb nmb

73 sudo firewall-cmd --permanent --add-service=samba

74 sudo setsebool -P samba_enable_home_dirs on

75 sudo setsebool -P samba_export_all_rw on

76 sudo semanage fcontext -a -t samba_share_t "/srv/samba/shared(/.*)?"

77 sudo restorecon -Rv /srv/samba/shared

78 vim /etc/samba/smb.conf

79 sudo systemctl restart smb nmb

80 sudo firewall-cmd --permanent --add-service=samba

81 sudo setsebool -P samba_enable_home_dirs on

82 sudo setsebool -P samba_export_all_rw on

83 sudo semanage fcontext -a -t samba_share_t "/srv/samba/shared(/.*)?"

复制代码
sudo dnf install samba samba-client samba-common-tools

创建共享文件用户

bash 复制代码
sudo mkdir -p /srv/samba/shared
sudo chown -R nobody:nobody  /srv/samba/shared
sudo chmod -R 0775 /srv/samba/shared
bash 复制代码
sudo useradd smart
sudo passwd 123456
sudo smbpasswd -a smart

配置文件

bash 复制代码
vim /etc/samba/smb.conf
bash 复制代码
# 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

	passdb backend = tdbsam

	printing = cups
	printcap name = cups
	load printers = yes
	cups options = raw

[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
[share]
	public = yes
	comment = share
	path = /home/miniodata
	browseable = yes
	guest ok = yes
	writable = yes
[shared]
    path = /srv/samba/shared
    browsable = yes
    writable = yes
    guest ok = yes
    valid users = smart
    create mask = 0775
    directory mask = 0775

重启Samba服务并设置开机自启动

bash 复制代码
sudo systemctl restart smb nmb
sudo systemctl enable smb nmb

配置防火墙和SELinux策略(如果可以直接把防火墙关了)

bash 复制代码
sudo firewall-cmd --permanent --add-service=samba
sudo firewall-cmd --reload

如果上述命令无法成功执行,可能需要手动添加Samba使用的端口

bash 复制代码
sudo firewall-cmd --permanent --add-port=139/tcp
sudo firewall-cmd --permanent --add-port=445/tcp
sudo firewall-cmd --permanent --add-port=137/udp
sudo firewall-cmd --permanent --add-port=138/udp
sudo firewall-cmd --reload

SELinux策略调整对于Samba服务的正常运行至关重要。首先设置SELinux布尔值(或者直接关了selinux)

bash 复制代码
sudo setsebool -P samba_enable_home_dirs on
sudo setsebool -P samba_export_all_rw on

然后,永久修改共享目录的SELinux上下文:

bash 复制代码
sudo semanage fcontext -a -t samba_share_t "/srv/samba/shared(/.*)?"
sudo restorecon -Rv /srv/samba/shared

最后在windows资源管理器里输入linux ip

会显示输入用户密码

smart

123456

创建桌面快捷方式 右键此电脑打开

在桌面右键创建快捷方式

重启也不会失效

相关推荐
非凡ghost10 小时前
Wireshark中文版(网络抓包工具)
网络·windows·学习·测试工具·wireshark·软件需求
ID_1800790547310 小时前
YouTube item_get_video接口认证方式:API密钥与OAuth2.0的选择与应用
服务器·windows·microsoft
yunianshu10 小时前
删除 Windows 保留名称文件指南
windows
zuozewei15 小时前
零基础 | AI编程工具 Claude Code 快速上手指南(Windows)
windows·ai编程
盘古工具16 小时前
创建分卷压缩文件:解决大文件传输难题
windows·winrar
玖釉-19 小时前
[Vulkan 学习之路] 16 - 最终章:渲染循环与同步 (Rendering & Presentation)
c++·windows·图形渲染
HelloRevit19 小时前
Windows Server SMB 共享文件 回收站
windows·c#
醇氧19 小时前
【Windows】安装mysql8
数据库·windows·mysql
十月不到底20 小时前
Windows 上安装 Volta
windows·npm
Merlyn1021 小时前
NVM介绍及Windows下的安装
windows·node.js·nvm