This tutorial is applicable to Centos and Ubuntu, and other Linux systems generally have the same configuration commands with high probability!
1. Turn off the firewall
1. Hundreds
View firewall status: systemctl status firewalld.service
Turn off the firewall: systemctl stop firewalld.service
Disable the firewall permanently: systemctl disable firewalld.service
2. Personality
View firewall status: sudo ufw status
Disable the firewall: sudo ufw disable
Second, install the samba server
1. Hundreds
yum install -y samba
2. Ubuntu
apt-get install -y samba
If it is sleeping during the installation process, you can use kill -9 process number to kill it, and then continue the installation!
3. Modify the samba configuration file
First backup the samba configuration file
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
and then modify
vim /etc/samba/smb.conf
Add the following code to global:
[global]
map to guest = Bad User # 开启匿名用户访问,这条注释要删掉!
Add the following code at the end of the file:
[share]
comment = This is samba dir
path = /home/share # 共享文件夹路径
read only = no # 关闭只读
create mask = 0777 # 创建文件权限
directory mask = 0777 # 文件夹权限
guest ok = yes
writable = yes
browseable = yes
The path item corresponds to the path of our shared folder, and the folder needs to be created in the corresponding path!
[share] corresponds to the folder displayed when we visit in the window!
4. Create a shared folder
mkdir /home/share
Note: After the shared folder is created, it may not be able to share in the window, because there is also a security mechanism SELinux in Linux, which will prevent you from accessing in the window;
There are two solutions here. 1. Turn off SELinux, but it is not recommended because it is a security mechanism; 2. Use the following commands to operate:
getenforce # If Enforcing is displayed, SELinux is running, but it is not recommended to close it! Just use the following two lines of code.
chcon -R -t samba_share_t shared folder path
chown to access samba account Shared folder path #The samba account here is the account of a common Linux user
For example:
chcon -R -t samba_share_t /home/share
chown admin /home/share # admin 是我Linux系统的普通用户
# 也可以自己新建一个用户去设置
5. Add the highest permission to the folder
chmod -R 777 /home/share
6. Add samba user
Generally use the Linux default user! That is, ordinary users of your Linux system!
smbpasswd - admin
enter password
Seven, restart the samba service
systemctl restart smb
8. Add the samba service to start automatically at boot
systemctl enable smb;systemctl enable smb.service
Nine, check the ip address
Ifconfig
checks the ip address in the ens33 network card
10. Access the samba server in Windows
\\IP address
At this point, the samba server configuration is set!
You can create files or folders, and then go to the /home/share folder in Linux to view, you will find that there will be files or folders just created; files created in Linux, using window access will also have corresponding document!