Install Samba server and configuration on linux (both windows and ios can connect and transfer files to each other) to solve the problem of sharing files between multiple devices
Preface
In the embedded system development application platform, tftp, nfs and samba servers are the most commonly used file transfer tools. tftp and nfs are commonly used transfer tools in the embedded Linux development environment, and samba is the file transfer tool between Linux and Windows. transfer tool.
Samba is a communication protocol that imitates the SMB communication protocol of Windows Network Neighborhood, "disguising" the Linux operating system as a Windows operating system, and transferring files through Network Neighborhood.
Linux operating system version: centos7
Samba server introduction
Samba is a free software that implements the SMB (Session MessageBlock) protocol on Linux systems to achieve file sharing and printer service sharing.
Samba server component
samba has two main processes smbd and nmbd . The smbd process provides file and print services, while nmbd provides NetBIOS name service and browsing support, helps SMB clients locate servers, and handles all UDP-based protocols.
Samba server installation
Check if it already exists
rpm -qa | grep samba
[root@localhost temp]# rpm -qa | grep samba
samba-common-libs-4.10.16-5.el7.x86_64
samba-common-tools-4.10.16-5.el7.x86_64
samba-4.10.16-5.el7.x86_64
samba-client-libs-4.10.16-5.el7.x86_64
samba-libs-4.10.16-5.el7.x86_64
samba-client-4.10.16-5.el7.x86_64
samba-common-4.10.16-5.el7.noarch
Install Samba
yum install -y samba
Check if the installation is successful
rpm -qa | grep samba
[root@192 ~]# rpm -qa | grep samba
samba-common-libs-4.10.4-11.el7_8.x86_64
samba-common-tools-4.10.4-11.el7_8.x86_64
samba-common-4.10.4-11.el7_8.noarch
samba-client-libs-4.10.4-11.el7_8.x86_64
samba-libs-4.10.4-11.el7_8.x86_64
samba-4.10.4-11.el7_8.x86_64
Among them: three programs: samba, samba-common, and samba-client are necessary.
Configure Samba
Modify the configuration file
There is actually only one main configuration file for the samba server, which is /etc/samba/samba.conf. This configuration file can be divided into two parts, one part is the global parameters, and the other part is the parameters related to shared resources.
1. 全局部分参数设置:
[global]
#与主机名相关的设置
workgroup = zkhouse <==工作组名称
netbios name = zkserver <==主机名称,跟hostname不是一个概念,在同一个组中,netbios name必须唯一
serverstring = this is a test samba server <==说明性文字,内容无关紧要
#与登录文件有关的设置
log file = /var/log/samba/log.%m <==日志文件的存储文件名,%m代表的是client端Internet主机名,就是hostname
max log size = 50 <==日志文件最大的大小为50Kb
#与密码相关的设置
security = share <==表示不需要密码,可设置的值为share、user和server
passdb backend = tdbsam
#打印机加载方式
load printer = no <==不加载打印机
-----------------------------------------------------------
2.共享资源设置方面:将旧的注释掉,加入新的
先取消[homes]、[printers]的项目,添加[temp]项目如下
[temp] <==共享资源名称
comment = Temporary file space <==简单的解释,内容无关紧要
path = /tmp <==实际的共享目录
writable = yes <==设置为可写入
browseable = yes <==可以被所有用户浏览到资源名称,
guest ok = yes <==可以让用户随意登录
Back up the configuration file first:
cp smb.conf smb.conf1
Modify configuration file
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
[temp]
comment = test Samba
path = /tmp
writable = yes
browseable = yes
guest ok = yes
Add Samba login user and password
useradd jenrey # jenrey为设置的Samba登录用户名
smbpasswd -a jenrey # jenrey为上面设置的Samba登录用户名,本句含义为给谁设置登录密码
Restart Samba
systemctl restart smb.service
Use Windows computer to connect to Linux Samba
Open "Run" in Windows system
win+r shortcut key
Enter the Samba address
\192.168.1.198
Note: The above address is the address of Linux where you installed Samba. If you don’t know, you can use the ifconfig command to check it.
If you need to enter a password, enter the previously declared account number and corresponding password.
Set Samba to start automatically at boot
systemctl enable smb.service
cd /etc/systemd/system/multi-user.target.wants/
ll
Start Samba manually
systemctl start smb.service
There is no permission to access the Linux share and the Samba service has no permission to access.
Solution 1:
Turn off SELIUNX
getenforce ;查看当前状态
Enforcing
setenforce 0;
Several states of SELINUX indicate:
enforcing: enforcing mode, which means that SELinux is running and has started to restrict domain/type correctly;
permissive: permissive mode: means that SELinux is running, but there will only be a warning message and will not actually restrict domain/type access. This mode can be used for debugging of SELinux;
disabled: Disabled, SELinux is not actually running.
Just use this method directly, it is simple and easy to understand;