How to quickly build Samba service in Linux system (including detailed steps!)

Hello, hello, I am the next artist! A novice who is learning Linux system!
Today I will introduce you to the samba service in Linux, which can share files between Linux and windows, Linux and Linux. Here are the detailed steps of the experiment.

-Overview

The biggest function of Samba is that it can be used for direct file sharing and print sharing between Linux and windows systems. Samba can be used for file sharing between windows and Linux, as well as resource sharing between Linux and Linux. Because of NFS( Network file system) can well complete the data sharing between Linux and Linux, so Samba is more used for data sharing between Linux and windows. 
 SMB is based on a client/server protocol, so a Samba server can serve as a file sharing server or a Samba client. For example, a Samba server that has been set up under Linux, the windows client The resource files on the Samba server can be shared through the SMB protocol. At the same time, the Samba server can also access files shared by other windows systems or Linux systems on the network.
 There are two services that make up Samba to run, one is SMB and the other is NMB; SMB is the core startup service of Samba, which is mainly responsible for establishing the dialogue between Linux Samba server and Samba client, verifying user identity and providing file and printing For system access, only the SMB service is started to realize file sharing and monitor TCP port 139; while the NMB service is responsible for resolution, similar to the function implemented by DNS, NMB can associate the workgroup name shared by the Linux system with its IP , If the NMB service is not started, you can only access the shared files through IP, listening on UDP ports 137 and 138.

Initialize the service

Initialize the virtual machine and close the firewall service, the previous article has detailed steps

  • Test connectivity
  • Server network card settings

Insert picture description here

  • Win10 client

Insert picture description here
Win10 client has connected to the server

experiment

  • Install samba service
[root@server1 ~]# yum -y install samba*
  • Write test file
[root@server1 ~]# mkdir /share
[root@server1 ~]# echo aaa > /share/a.txt
[root@server1 ~]# cat /share/a.txt 
aaa
  • Setting permissions
[root@server1 ~]# chmod -R 777 /share
  • Change the configuration file, add the following program at the end of the configuration file
[share]
        comment = a share direcotry
        path = /share
        read only = yes
        valid users = lisi, tom
        write list = lisi
        hosts allow = 192.168.1.
  • Start service
[root@server1 ~]# systemctl start smb
[root@server1 ~]# systemctl start nmb
  • Create samba user
[root@server1 ~]# pdbedit -a -u lisi   #创建samba用户设置密码
new password:
retype new password:
[root@server1 ~]# pdbedit -a -u tom
new password:
retype new password:

Set the password to 123456, the following interface appears
Insert picture description here

  • Client Win10 test

The URL of the server is 192.168.1.100Insert picture description here

Enter lisi and password to
Insert picture description here
Insert picture description here
enter the share folder
Insert picture description here

  • Create a new b file

Insert picture description here
The creation is successful, indicating that the user lisi has read and write permissions and the
tom user enters the
Insert picture description here
Insert picture description here
new file, which indicates that there is no write permission and the experiment is normal.

  • Linux client test

lisi user
Insert picture description here

[root@server3 ~]# systemctl stop firewalld.service   #关闭防火墙
[root@server3 ~]# setenforce 0      #关闭核心防护
[root@server3 ~]# smbclient //192.168.1.10/share -U lisi         #连接服务器
Enter SAMBA\lisi's password: 
Domain=[SERVER1] OS=[Windows 6.1] Server=[Samba 4.10.4]
smb: \> put anaconda-ks.cfg     #上传anaconda-ks.cfg,验证写权限
putting file anaconda-ks.cfg as \anaconda-ks.cfg (28.2 kb/s) (average 28.2 kb/s)
smb: \> get a.txt               #下载a.txt验证读权限
getting file \a.txt of size 4 as a.txt (1.3 KiloBytes/sec) (average 1.3 KiloBytes/sec)
smb: \> quit

Client share directory
Insert picture description here
tom user connection

Insert picture description here

The server share directory Insert picture description here
tom has not been uploaded successfully. It can be seen that tom has read permission but no write permission.

Mount the samba shared folder to the root directory

Insert picture description here

[root@server3 ~]# mkdir /mydata
[root@server3 ~]# mount -o username=lisi //192.168.1.10/share /mydata
Password for lisi@//192.168.1.10/share:  ******
[root@server3 ~]# cd /mydata
[root@server3 mydata]# touch aaa
[root@server3 mydata]# touch 123123

The file exists in the server shared directory The Insert picture description here
above experiment is normal

If you have any questions, you can comment or chat privately, and they will reply!
If you find it useful, you are welcome to bookmark, comment and forward! ! !

Guess you like

Origin blog.csdn.net/qyf158236/article/details/108466172