Samba file sharing service
Samba origin:
In the early days, most files shared between different hosts were transmitted using the FTP protocol, but the FTP protocol could only transfer files but could not directly modify the data of the other host. This is really inconvenient, as a result, the NFS open source file sharing program emerged: NFS (NetworkFile System) is a lightweight file sharing service that can mount remote host data from multiple Linux Hosts to a local directory, file Sharing between Linux and Windows systems is not supported.
Later in 1991, Tridgwell, a student, developed the SMB protocol and Samba service program to solve the problem of file sharing between Linux and Windows systems.
SMB (Server Messages Block) Protocol: the protocol for sharing resources such as files or printers in a LAN.
At that time, Tridgwell wanted to register the SMBServer trademark, but was rejected because SMB was meaningless characters. After Tridgwell's constant reading of the dictionary, he finally found the name of a Latin dance-SAMBA, the name of this enthusiastic dance exactly contains SMB (SAMBA), so this is the origin of the Samba program name.
The Samba service is an open source file sharing software based on the SMB protocol and composed of the server and client. It implements file sharing between Linux and Windows systems.
Required Host Configuration:
Host Name |
Operating System |
IP address |
Samba Shared Server |
Red Hat RHEL6 Operating System |
192.168.0.141 |
Client |
Red Hat RHEL6 Operating System |
192.168.0.142 |
Client |
Windows 7 Operating System |
192.168.0.110 |
[Root @ host1 ~] # Yum-y install samba
[Root @ host1 ~] # Service smb restart
[Root @ host1 ~] # Chkconfig smb -- list
Smb 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
[Root @ host1 ~] # Cat/etc/samba/smb. conf | grep-v "#" | grep-v ";" | grep-v "^ $"
[Global]
Workgroup = MYGROUP
Server string = Samba Server Version % v
Log file =/var/log/samba/log. % m
Max log size = 50
Security = user
Passdb backend = tdbsam
Load printers = yes
Cups options = raw
[Homes]
Comment = Home Directories
Browseable = no
Writable = yes
[Printers]
Comment = All Printers
Path =/var/spool/samba
Browseable = no
Guest OK = no
Writable = no
Printable = yes
The filtered configuration file:
[Global] |
|
# Global parameters. |
| |
Workgroup = MYGROUP |
# Workgroup name. |
| |
Server string = Samba Server Version % v |
# Server Introduction Information. The parameter % v is used to display the SMB version number. |
| |
Log file =/var/log/samba/log. % m |
# Define the location and name of the log file. The parameter % m is the visiting host name. |
| |
Max log size = 50 |
# Defines the maximum log file capacity as 50Kb. |
| |
Security = user |
# There are four security verification methods in total. |
| |
# Share: the visitor does not need to verify the password, which is more convenient but has poor security. |
| |
# User: access can be established only after the password provided by the visiting host is verified by the SMB service, which is more secure. |
| |
# Server: use an independent remote host to verify the password provided by the visiting host (centralized management account ). |
| |
# Domain: Use PDC for verification |
| |
Passdb backend = tdbsam |
# Define three types of user backend. |
| |
# Smbpasswd: Use the smbpasswd command of the SMB service to set the SMB password for system users. |
| |
# Tdbsam: Create a database file and use pdbedit to create an SMB independent user. |
| |
# Ldapsam: Performs Account Verification Based on the LDAP service. |
| |
Load printers = yes |
# Set whether to share the printer device when the Samba service starts. |
| |
Cups options = raw |
# Printer Options |
[Homes] |
|
# Sharing Parameters |
| |
Comment = Home Directories |
# Description |
| |
Browseable = no |
# Specify whether the sharing is visible in "Network neighbors. |
| |
Writable = yes |
# Define whether a write operation is allowed, which is opposite to "read only. |
[Printers] |
|
# Printer sharing Parameters |
| |
Comment = All Printers |
|
| |
Path =/var/spool/samba |
# The actual path of the shared file (important ). |
| |
Browseable = no |
|
| |
Guest OK = no |
# Whether all users are visible is equivalent to the "public" parameter. |
| |
Writable = no |
|
| |
Printable = yes |
|
The standard Samba sharing parameters are as follows:
Parameters |
Function |
[Linuxprobe] |
Share Name: linuxprobe |
Comment = Do not arbitrarily modify the database file |
Warn users not to modify databases at will |
Path =/home/database |
Shared Folder in/home/database |
Public = no |
Disable all visibility |
Writable = yes |
Allow write operations |
The password authentication method of the Samba service makes shared files more secure, so that only trusted users can access the shared files and the verification process is simple. To use the Password Authentication mode, we need to first create an independent database for the Samba service.
Step 2: Check whether the current user authentication mode is used
[Root @ host1 ~] # Cat/etc/samba/smb. conf
......
Security = user
Passdb backend = tdbsam
......
Step 2: Create a shared folder:
[Root @ host1 ~] # Mkdir/database
Step 2: Description of Shared Folder Information.
Append the configuration parameters of the shared folder to the bottom of the main configuration file of the SMB service:
[Database]
Comment = Do not arbitrarily modify the database file
Path =/database
Public = no
Writable = yes
Save the smb. conf file and restart the SMB service:
[Root @ host1 ~] # Service smb restart
Step 2: Access via Windows Host
Enter the remote host information in the Windows host running box.
An error is reported when you access the Samba service.
In this case, we need to disable the firewall (or clear the firewall rules) and modify SElinux rules.
Step 2: Clear the firewall rule chain:
[Root @ host1 ~] #/Etc/init. d/iptables stop
Or:
[Root @ host1 ~] # Iptables-F
[Root @ host1 ~] # Service iptables save
Step 2:Create an independent account for the SMB service.
For Windows systems, authentication is required before access to sharing. In the SMB service configuration file, the password database background type is tdbsam. Therefore, this account and password are the independent account information of the Samba service, we need to use the pdbedit command to create the user database of the SMB service.
The pdbedit command is used to manage the account information database of the SMB service. The format is "pdbedit [Option] account ".
Parameters |
Function |
-A User Name |
Create Samba users |
-X User Name |
Delete Samba users |
-L |
List users |
-Lv |
List user details |
Create a system user:
[Root @ host1 ~] # Useradd smbuser
Upgrade the System user to an SMB User:
[Root @ host1 ~] # Pdbedit-a-u smbuser
New password: // set the independent password for the SMB service
Retype new password:
Unix username: smbuser
NT username:
......
Step 2:Allow SELinux rules
Set the ACL permission for the shared directory to add the smbuser User:
[Root @ host1 ~] # Setfacl-m u: smbuser: rwx/database
Allow SELinux to share the Boolean value of the home directory for SMB users:
[Root @ host1 ~] # Setsebool-P samba_enable_home_dirs on
Set the SELinux security context of the shared directory properly:
[Root @ host1 ~] # Chcon-t samba_t _t-R/database
Restart the service:
[Root @ host1 ~] # Service smb restart
Step 2:Use Windows host to verify sharing results
Use the SMB service and create a file
Implement data sharing between Linux systems
Install the cifs-utils software package on the client:
[Root @ host2 ~] # Yum-y install cifs-utils
[Root @ host2 ~] # Smbclient-L 192.168.0.141 // view what shares are provided by the 141 Server
Enter root's password:
Anonymous login successful
Domain = [MYGROUP] OS = [Unix] Server = [Samba 3.6.23-20. el6]
Sharename Type Comment
--------------------
Database Disk Do not arbitrarily modify the database file
IPC $ IPC Service (Samba Server Version 3.6.23-20. el6)
......
[Root @ host2 ~] # Mkdir/mntsmb
[Root @ host2 ~] # Vim/etc/fstab
// 192.168.0.141/database/mntsmb cifs username = smbuser, password = 123456, domain = MYGROUP, _ netdev 0 0
[Root @ host2 ~] # Mount-
[Root @ host2 ~] # Mount | grep/mntsmb
// 192.168.0.141/database on/mntsmb type cifs (rw)
[Root @ host2 ~] # Cat/mntsmb/smb.txt
Hello
PS: write a lot of content, but the actual configuration is very few steps, it is relatively simple!