Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

12.1 SAMBA file sharing service


May 24, 2021 That's what Linux should learn



The FTP file transfer service explained in the last chapter can actually make file transfer between hosts simple and convenient, but the nature of the FTP protocol is to transfer files, not share files, so it is a hassle to modify the contents of files directly on the server through the client.

In 1987, Microsoft and Intel co-established the SMB (Server Messages Block, Server Message Block) protocol, which aims to solve the problem of sharing resources such as files or printers within a local area network, which also makes it easier to share files between multiple hosts. B y 1991, Tridgwell, who was still in college at the time, had developed the SMBServer service based on the SMB protocol to address file sharing between Linux and Windows systems. T his is an open source file sharing software that enables file sharing between Linux and Windows systems with a simple configuration. A t the time, Tridgwell wanted to register the software's name SMBServer as a trademark, but the trademark office rejected the application for SMB's meaningless characters. T hen Tridgwell looked through the dictionary and suddenly saw a Latin dance name, Samba, and the enthusiastic dance name happened to contain "SMB", so the name of the Samba service was born (see Figure 12-1). Samba service programs are now the best choice for sharing files between Linux and Windows systems.

12.1 SAMBA file sharing service

Figure 12-1 The logo of the Samba service program

The configuration method of the Samba service program is similar to that of many of the services explained earlier, starting with the installation of the Samba service program through the Yum repository (the name of the Samba service program also happens to be the name of the package):

[root@linuxprobe ~ ]# yum install samba Loaded plugins: langpacks, product-id, subscription-manager .................. O mit some of the output information... Installing: samba x86_64 4.1.1-31.el7 rhel 527 k Transaction Summary

  1. Install 1 Package
  2. Total download size: 527 k
  3. Installed size: 1.5 M
  4. Is this ok [y/d/N]: y
  5. Downloading packages:
  6. Running transaction check
  7. Running transaction test
  8. Transaction test succeeded
  9. Running transaction
  10. Installing : samba-4.1.1-31.el7.x86_64 1/1
  11. Verifying : samba-4.1.1-31.el7.x86_64 1/1
  12. Installed:
  13. samba.x86_64 0:4.1.1-31.el7
  14. Complete!

After installing, open the main profile of the Samba service program and find that there are as many as 320 lines! A re you scared? B ut a closer look reveals that most of them are actually lines of comment information that begin with a hashtag. There is Mr. Liu Wei in, certainly will not let everyone go to "dead gnaw" these content.

[root@linuxprobe ~]# cat /etc/samba/smb.conf

This is the main Samba configuration file. For detailed information about the

  1. # options listed here, refer to the smb.conf(5) manual page. Samba has a huge
  2. # number of configurable options, most of which are not shown in this example.
  3. #
  4. # The Official Samba 3.2.x HOWTO and Reference Guide contains step-by-step
  5. # guides for installing, configuring, and using Samba:
  6. # http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
  7. #
  8. # The Samba-3 by Example guide has working examples for smb.conf. This guide is
  9. # generated daily: http://www.samba.org/samba/docs/Samba-Guide.pdf
  10. #
  11. # In this file, lines starting with a semicolon (;) or a hash (#) are
  12. # comments and are ignored. This file uses hashes to denote commentary and
  13. # semicolons for parts of the file you may wish to configure.
  14. #
  15. # Note: Run the "testparm" command after modifying this file to check for basic
  16. # syntax errors.
  17. #
  18. ………………省略部分输出信息………………

Since there are too many comment lines in the main profile of the Samba service provider to analyze the important parameters inside, the main configuration file is changed to a name, then the cat command is used to read into the main configuration file, and then the -v parameter (reverse selection) is added after the grep command, removing all the hashtags (s) and semi-numbers (; A t the beginning of the comment information line, the remaining blank line can be represented and defiltered using the s$parameter, and finally the filtered available parameter information is overwritten to the original file name via a redirector override. The parameters of the remaining Samba service program after filtering are not complicated, and tables 12-1 list the parameters and the corresponding notes in order to make it easier for the reader to access the parameters.

The parameters and roles in the Samba service program in Table 12-1

The global # global parameters. Workgroup S MyGroup # Working Group Name Server String S Samba Server Version% V # server introduction information, parameter% V Shows SMB Version Number log file s /var/log/samba/log.%M # Defines the location and name of the log fileParameter% M is Visiting Host Name Max log size s 50 # definition of the maximum capacity of the log file is 50KB Security S User # security verification method, A Total of 4

share: Visiting hosts do not need to verify passwords;

  1. #user:需验证来访主机提供的口令后才可以访问;提升了安全性
  2. #server:使用独立的远程主机验证来访主机提供的口令(集中管理账户)
  3. #domain:使用域控制器进行身份验证
  4. passdb backend = tdbsam #定义用户后台的类型,共有3种
  5. #smbpasswd:使用smbpasswd命令为系统用户设置Samba服务程序的密码
  6. #tdbsam:创建数据库文件并使用pdbedit命令建立Samba服务程序的用户
  7. #ldapsam:基于LDAP服务进行账户验证
  8. load printers = yes #设置在Samba服务启动时是否共享打印机设备
  9. cups options = raw #打印机的选项
  10. [homes] #共享参数
  11. comment = Home Directories #描述信息
  12. browseable = no #指定共享信息是否在“网上邻居”中可见
  13. writable = yes #定义是否可以执行写入操作,与“read only”相反
  14. [printers] #打印机共享参数
  15. comment = All Printers
  16. path = /var/spool/samba #共享文件的实际路径(重要)。
  17. browseable = no
  18. guest ok = no #是否所有人可见,等同于"public"参数。
  19. writable = no
  20. printable = yes
  21. [root@linuxprobe ~]# mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
  22. [root@linuxprobe ~]# cat /etc/samba/smb.conf.bak | grep -v "#" | grep -v ";" | grep -v "^$" > /etc/samba/smb.conf
  23. [root@linuxprobe ~]# cat /etc/samba/smb.conf