Samba usage Overview
-Samba Server
Samba protocol Basics
After NetBIOS appeared, Microsoft implemented a network file/print service system using NetBIOS. This system sets a file sharing protocol based on NETBIOS, which Microsoft calls Server Message Block (SMB) protocol. Microsoft uses this Protocol in their LAN Manager and Windows NT Server systems to share printers, serial ports, and communication abstractions (such as named queues and mail slots) between different computers ).
With the popularity of the Internet, Microsoft hopes to extend this Protocol to the Internet, becoming a standard for computers on Inter Net to share data with each other. Therefore, it sorts out the existing SMB protocol with few technical documents, renames it CIFS (Common Internet File System), and intends to disassociate it from netbios, try to make it a standard protocol on the Internet.
Therefore, to integrate windows and Unix computers, the best way is to install software that supports SMB/CIFS on UNIX computers, so that Windows customers do not need to change the settings, you can use resources on UNIX computers just like using Windows NT servers. Samba is a software used to implement SMB. its working principle is to enable NetBIOS (Communication Protocol of windows95 network neighbors) and SMB (Server Message Block) these two protocols run on TCP/IP communication protocols, And the netbeui protocol of Windows enables UNIX computers to be seen by Windows computers on network neighbors. Its functions include:
1. Share the Linux disk to Win95/NT
2. Share Win95/NT disk to Linux machine
3. Share the Linux printer with Win95/NT
4. Share the Win95/NT printer with the Linux machine.
At the same time, its file service functions are higher than the NT System, and the user's disk space is limited before Windows2000.
Samba Configuration
At the time of writing this article, Samba has reached 2.2.2. You can use ftp://samba.org/pub/samba/binary_pa..201711013.i386.rpmto get the latest rpminstallation package. Then run the rpm-uvh samba-2.2.2-20011013.i386.rpm to install or upgrade it. After the installation is complete, you can see a directory such as/etc/samba, which stores some samba-related files, most of which is smb. conf. Now let's talk about its configuration options based on the configuration file:
Global settings:
Workgroup = mygroup
Define the Working Group or domain of the Samba server (if security = domain is set below ).
Server String = My Samba Server
Set the machine description. When we access the machine through a network neighbor, we can see this content in the remarks, and we can also use the variables set by Samba. Here we will talk about the variables defined by Samba:
% S = current service name (if any)
% P = root directory of the current service (if any)
% U = User Name of the current service (if any)
% G = the active working group that the current user says is in
% U = User Name of the current Dialog
% G = Main workgroup of the user in the current Dialog
% H = home directory of the current service user
% V = SAMBA service version.
% H = Host Name of the machine running the samba Service
% M = client NetBIOS Name
% L = server NetBIOS Name
% M = client host name
% N = NIS server name
% P = The Home Directory of the NIS Service
% R = protocol level used (value can be core, coreplus, lanman1, lanman2, nt1)
% D = ID of the current service process
% A = client structure (only samba, wfwg, WINNT, and Win95 can be identified)
% I = Client IP Address
% T = current date and time
Hosts allow = network or host
Here, you can set the network and Host IP addresses that are allowed to access, for example, to allow access from 192.168.1.0/24 and 192.168.2.1/32, host allow = 192.168.1. 192.168.2.1 127.0.0.1 (Add ". ", each project is separated by a space, remember to add the local machine)
Printcap name = printcapfile
Obtain the description of the printer in the printcapfile (usually/etc/printcap) file.
Load printers = Yes | No
Set whether to automatically share the printer without setting the following [Printer] section.
Printing = printsystemtype
Defines the printing system type. The default value is LPRng. The options include BSD, sysv, PLP, LPRng, Aix, HPUX, and QNX.
Guest account = pcguest
Define the visitor account and add this account to/etc/passwd. Otherwise, it will use the default nobody.
Log File = logfilename
Define the location of the record file logfilename (usually/var/log/samba/% m. Log)
Max log size = size
Defines the size of the record file (unit: KB. If it is 0, the size is not limited)
Security = security_level
Defines the security level of Samba, from low to high: Share, user, server, domain. The verification methods are as follows:
Share: no security level. Any user can access resources on the server without a user name or password.
User: The default configuration of Samba. Users must provide the user name and password for authentication before accessing shared resources.
Server: similar to the user security level, but the user name and password are submitted to another server for verification, for example, submitted to an NT server. If the submission fails, it is returned to the user security level.
Domain: This security level requires that a Windows primary domain controller exist on the network. Samba submits the user name and password to it for verification.
The following three security levels require users to have system accounts on their Linux machines. Otherwise, it cannot be accessed.
Password Server =
It is necessary to set the current security to server or domain.
Password level = N
This is intended for SMB customers such as OS/2. When sending user passwords, such systems convert the passwords into uppercase and then send them, this is inconsistent with Samba's password. This parameter can be used to set the number of allowed upper-case letters in the password. In this way, Samba will re-convert the received password based on this number, verify the correctness of the new password. The larger the N value, the more combinations, the longer the verification time, and the lower the security. For example, if n = 2, the user's password is ABCD, but if it is actually ABCD, Samba will reorganize the case of this ABCD. The combined result can be: ABCD, ABCD, ABCD, ABCD,
ABCD, ABCD.
So if there is no need, set N to zero. In this case, Samba only tries twice. One is the password received, and the other is the password in lower case.
Username level = N
This is the username, which is similar to the preceding one.
Encrypt passwords = Yes | No
Set whether to encrypt the password. Samba itself has a password file/etc/samba/smbpasswd. If the password is not encrypted, the plaintext password is transmitted between the client and the server during the verification session, samba directly verifies the password with the/etc/samba/smbpasswd password file in Linux. However, neither Versions later than Windows 95 OS/R2 nor Versions later than Windows NT SP3 transmit plaintext passwords by default. To enable these systems to transmit plaintext passwords, they must be changed in their registries, it is troublesome. A good way is to set this switch to yes.
SMB passwd file = smbpasswordfile
Set the smbpasswordfile that stores the samba User Password (usually/etc/samba/smbpasswd ).
SSL ca certfile = sslfile
When Samba compilation supports SSL, You need to specify the SSL Certificate location (typically in/usr/share/SSL/certs/ca-bundle.crt ).
Unix Password Sync = Yes | No
Passwd program =/usr/bin/passwd % u
Passwd chat = * New * UNIX * password * % N
* Retype * New * UNIX * password * % N
* Passwd: * All * authentication * tokens * Updated * successfully *
Can these three settings change the password of a UNIX system from a Windows application?
Username map = usermapfile
Specify the user ing file (usually/etc/samba/smbusers). When we specify a line of root = administrator admin in this file, when the client user is admin or administrator, the connection will be treated as the user root.
Include = machineconffile
Specify different configuration files machineconffile for connections to different machines (generally for flexible management and use of/etc/samba/smb. conf. % m. Because Samba variables are used to associate the configuration file with the NetBIOS name of the client, it is easy to control the permissions and settings of these clients ).
Socket Options = tcp_nodelay so_rcvbuf = 8192 so_sndbuf = 8192
This is a number of network socket parameters that can achieve the best file transmission performance. Related options include so_keepalive, so_reuseaddr, so_broadcast, iptos_lowdelay, iptos_throughput, so_sndlowat (*), so_rcvlowat (*), and numbers with the * sign. Generally, only iptos_lowdelay is used in the local network. If there is a local network, iptos_lowdelay tcp_nodelay is used. If it is a wide area network, try iptos_throughput.
Interfaces = interface1 interface2
If you have multiple network interfaces, you must specify them here. For example, interface = 192.168.12.2/24 192.168.13.2/24
Remote browse sync = host (subnet)
Where to obtain the synchronization information of the browsing list, if host (such as 192.168.3.25) or the whole subnet (192.168.5.255) is used ).
★Here we will explain what is browse ):
In the SMB protocol, to access network resources, computers need to know the list of resources on the network (for example, using network neighbors in Windows to view accessible computers ), this mechanism is called browse ). Although the SMB protocol often uses the broadcast method, if you use the broadcast method every time to understand the current network resources (including the computers providing services and the service resources on each computer ), this requires a lot of network resources and a long time to search. Therefore, it is best to maintain a list of network resources in the network to facilitate searching for network resources. You can search for resources only when necessary, for example, using the search computer function in windows.
However, it is not necessary for each computer to maintain the entire resource list. The task of maintaining the current resource list in the network is completed by several special computers on the network. These computers are called browser, these browsers record broadcast data or query name servers to record various resources on the network.
Browser is not a computer specified in advance, but generated between normal computers through automatic recommendations. Different computers can set different weights for recommendations based on their ability to provide services. To ensure that the network browsing is still normal when a browser is down, there are often multiple browsers in the network, one for the master browser and the other for the backup browser.★
Remote announce = host (subnet)
Specify these machines to advertise themselves to the network, instead of using browser.
Local Master = Yes | No
This parameter specifies whether nmbd tries to become the local host browser. The default value is yes. If it is set to no, the Samba server will never become the local host browser. However, even if yes is set, the Samba server becomes the main browser. Only participate in the selection of the local host browser.
OS level = N
The value of N is an integer, which determines whether nmbd has the opportunity to become the local master browser in the Working Group of the local broadcast area. The default value is zero, and zero means that nmbd has no browsing choice. If you want nmbd to have a better chance of becoming the local host browser, you can set it to 65.
Domain Master = Yes | No
This parameter makes nmbd a domain browser, obtains the browsing list of each local host browser, and submits the browsing list of the entire domain to each local host browser.
Preferred master = Yes | No
This parameter specifies whether nmbd is the primary browser in the working group. If yes is specified, nmbd forces a browser selection at startup.
★Domain Master and local master
The concepts of working groups and domains are equally useful in browsing. They are used to differentiate and maintain multiple computers that browse data in the same group. In fact, their difference lies in the authentication method. Each computer in the Working Group is basically independent and authenticates the client access independently, and one or more domain controllers exist in the domain, stores authentication information that is valid for the entire domain, including user authentication information and authentication information of the member computers in the domain. When you browse data, you do not need to authenticate the information. Microsoft extends the workgroup to a domain to form a hierarchical directory structure that combines the original browsing and directory services, A strategy to expand the scope of Mircrosoft network services.
Both the workgroup and domain can span multiple subnets. Therefore, there are two types of browsers in the Network: domain master browser, which is used to maintain the browsing data of the entire workgroup or domain, the other is the local master browser, which is used to maintain the browsing data in the subnetwork. It communicates with the domain master browser to obtain all the browsing data. The division of the two browser types is mainly because the browsing data relies on gossip network broadcast to obtain the resource list. different subnets can exchange resource lists only through the communication capability between browsers.
However, to browse resources of multiple subnets, you must use the DNS resolution method of the NBNS name server. Without the help of NBNS, the computer cannot obtain the NetBIOS Name of a computer outside the subnet. The local master browser also needs to query the NetBIOS name server to obtain the domain master browser name to exchange network resource information.
Due to the special nature of the domain controller in the domain, the domain controller tends to be used as the browser, and the master Domain Controller should be used as the domain master browser. They set a large weight during the recommendation.★
Preserve case = Yes | No
Short preserve case = Yes | No
Specifies the case sensitivity when copying DoS Files. The default value is no.
Default case = Lower | Upper
The default value of all DoS Files is uppercase or lowercase.
Case Sensitive = Yes | No
It is case sensitive and generally no. Otherwise, some problems may occur.
Sharing settings:
★Shared resources:
Each SMB server can provide external file or print services, and each shared resource needs to be assigned a sharing name, which will be displayed in the server's resource list. If the last letter of a resource name is $, the shared name is hidden and cannot be directly displayed in the browsing list, but can only be accessed by directly accessing the name. In the SMB protocol, to obtain the list of resources provided by the server, you must use a hidden Resource Name IPC $ to access the server. Otherwise, you cannot obtain the list of system resources.★
There is a strange section in the sharing settings:
[Homes]. In the smb. conf file, no specific contents such as paths are set for this directory. When the client sends a service request, it searches for the service with the specified content in other parts of the smb. conf file. If these services are not found and the homes segment is provided, search the password file to get the user's home directory. Using the homes segment, Samba can obtain and share the user's home directory. The following are the basic settings for this section.
[Homes]
Comment = home directory
Browseable = No
Writable = Yes
The following is an example of a normal shared Configuration:
[Myshare]
Comment = grind's file
Path =/home/grind
Allow hosts = host (subnet)
Deny hosts = host (subnet)
Writable = Yes | No
User = user (@ Group)
Valid users = user (@ Group)
Invalid users = user (@ Group)
Read list = user (@ Group)
Write list = user (@ Group)
Admin list = user (@ Group)
Public = Yes | No
Hide dot files = Yes | No
Create mode = 0755
Directory mode = 0755
Sync always = Yes | No
Short preserve case = Yes | No
Preserve case = Yes | No
Case Sensitive = Yes | No
Mangle case = Yes | No
Default case = upper | Lower
Force user = grind
Wide links = Yes | No
Max connections = 100
Delete readonly = Yes | No
Specifically, myshare in [] specifies the sharing name, which is generally the name of the folder that can be seen in the network neighbor.
Comment refers to the remarks on share change.
Path specifies the shared path, which can be used with the samba variable. For example, you can specify Path =/data/% m. If the NetBIOS Name of a machine is grind, it enters the/data/grind directory when accessing the share of myshare, for machines whose NetBIOS name is glass, enter the/data/Glass directory.
Allow hosts and deny hosts are the same as the previous global settings.
Writeable specifies whether the directory is writable by default. You can also use readonly = No to set writeable.
Users can set all users who may use the shared resource or use @ group to represent all members of the group. Different projects are separated by spaces or commas.
Valid users specifies the users and groups that can use the shared resource.
Invalid users specifies the users and groups that cannot use the shared resource.
Read List specifies users and groups that can only read the shared resource.
Write List specifies the users and groups that can read and write the shared resource.
Admin List specifies the users and groups that can manage the shared resources (including read/write and permission granting.
Public indicates whether the shared resource can be accessed by the visitor's account. This switch is also called guest OK. Therefore, guest OK = yes in some configuration files is actually the same as public = yes.
Hide dot files indicates whether to hide files starting with "." Like UNIX.
Create mode indicates the attributes of the newly created file, which is generally 0755.
Directory mode indicates the attribute of the newly created Directory, which is generally 0755.
Sync always indicates whether to perform synchronization after writing the shared resource.
Short preserve case indicates that the file name is case-insensitive.
Preserve case indicates case sensitivity.
Case Sensitive indicates whether it is case sensitive. Generally, no is selected. Otherwise, an error may occur.
Mangle case indicates the mixed case.
Default case indicates whether all the default file names are in uppercase or lowercase.
Force user forces the owner of the file to be created. If I have a directory that allows the guest to be written, the guest can be deleted. If I use force user = grind to force the object to be created, the owner is grind, and the create mask = 0755, in this way, the guest cannot be deleted.
Wide links indicates whether to allow connections with shared external symbols. For example, a connection in a shared resource directs to a file or directory in a non-shared resource. Setting wide links = No makes the connection unavailable.
Max connections = n sets the number of simultaneous connections to n.
Delete readonly indicates whether to delete a file already defined as read-only in a shared resource.
There are two types of special sharing: Optical Drive and printer
Shared settings of the optical drive:
[CDROM]
Comment = grind's CDROM
Path =/mnt/CDROM
Public = Yes
Browseable = Yes
Root preexec =/bin/Mount-T iso9660/dev/cd0/mnt/CDROM
Root postexec =/bin/umount/mnt/CDROM
Here, root preexec indicates that the mount command is run as root during connection, while root postexec indicates that umount is run as root During disconnection, which effectively achieves shared Optical Drive.
Printer sharing settings:
[Printers]
Path =/var/spool/samba
Writeable = No
Guest OK = Yes
Printable = Yes
Printer Driver = HP LaserJet 5l
Printable indicates that the printer can be printed, guest OK indicates that visitors can also print, path indicates that the printed file queue is temporarily placed in the/var/spool/samba directory. The role of the printer driver is to specify the printer type, so that we can automatically install the driver when installing the network printer without selecting.
Add User:
It is convenient to add users to Samba. Generally, smbadduser is used. The usage is smbadduser unixid: netid. For example, if your local machine has a user named grind, you can use smbadduser grind: grind, in this way, grind is used for the user name when accessing from the network neighbor. If smbadduser grind: glass is used, the user name provided by the network neighbor is glass instead of grind.
This is basically the setting of the Samba server. I think the above is almost all used in the application, so some unimportant ones are omitted, for more detailed information, use man SMB. conf reference. /Dev/null
3. mf_wrapper is a magic filter file and is a filtering rule. Content:
Mf_rule_dir = '/usr/share/printconf/mf_rules'
Mf_rules = $ mf_rule_dir/MF [[] [[]-*
Tmp_file = 'mktemp/tmp/printconf. xxxxxx ''' Exit 1
Cat./MF. cfg $ mf_rules | M4>; $ tmp_file
If [-n "$ debug"]; then
Case "$ debug" in
2)
Debugstring = "-- debug"
;;
3)
Debugstring = "-- debug"
; 4)
Debugstring = "-- debug"
;;
5)
Debugstring = "-- debug"
;;
*)
Debugstring = "-- debug"
;;
Esac
Else
Debugstring = ""
Fi
# Run magic Filter
/Usr/bin/magicfilter-T $ tmp_file $ debugstring $ *
The subsequent commands are the same as those for FTP. You can use get to download files and put to upload files. You can use help to view the commands.
Another method is to use a file system (this method is required to ensure that your kernel supports smbfs. If not, you must select file systems ---> when compiling the kernel; network file systems --->; SMB File System Support (to mount Windows shares etc .)):
Smbmount // ip address or NetBIOS name/Shared Resource Name/local mount point [-O option]
Commonly used options include username =, password =, and guest (specify to use guest for access, without providing a password. If the preceding parameter is username = guest, the password is required ), RO (sometimes set to read-only mode for System Security), RW, and multiple options are separated by commas.
Alternatively, you can use Mount-T smbfs [-O option] // ip or NetBIOS name/Shared Resource Name/local mount point to implement the same function.
Example:
Smbmount // glass/littlep/test-O guest or mount-T smbfs-O guest // glass/littlep/test, then you can access/test to use resources on the network.
If you do not need to use it, you can simply use smbumount/test or umount/test to remove the hook.
About Samba functions (share the Linux disk to Win95/NT, share the Linux printer to Win95/NT, and share the Win95/NT printer to the Linux machine. , Share Win95/NT disk to Linux machine), the first two are Samba server content and the last two are samba client segment content, both of my articles have introduced their implementation methods. However, Samba is a powerful tool that cannot be used to describe all its functions in detail, and it is limited by my knowledge, if you have any questions, please point out that I hope you will have more exchanges.