FTP File transfer service can really make the file transfer between hosts simple and convenient , however FTP The essence of the protocol is to transfer files , Instead of sharing files , Therefore, it is a troublesome thing to modify the file content directly on the server through the client .

1987 year , Microsoft and Intel have jointly formulated SMB(Server Messages Block, Server message block ) agreement , It aims to solve the problem of sharing files or printers in LAN , This also makes it easier to share files among multiple hosts . here we are 1991 year , I was still in college Tridgwell In order to solve Linux System and Windows File sharing between systems , be based on SMB The protocol developed SMBServer Service program . This is an open source file sharing software , It can be realized through simple configuration Linux System and Windows File sharing between systems . at that time ,Tridgwell Want to put the name of this software SMBServer To register as a trademark , However, it was recognized by the trademark office SMB It's a meaningless character that rejects the application . later Tridgwell Keep going through the dictionary , Suddenly I saw the name of a Latin dance —Samba, And this passionate dance name just contains “SMB”, therefore Samba The name of the service program was born .Samba The service program is now in Linux System and Windows The best way to share files between systems .

One 、 install Samba service :

use first rpm -qa | grep samba Command to see if the system is installed Samba service

without , Use yum install samba Command to install

... The output information of the middle part is omitted ...

Use rpm -qa | grep samba Command to view the installed Samba Information

service smb start        # start-up Samba service

service smb stop        # stop it Samba service

service smb restart     # Restart Samba service

service smb status     # see Samba Status of the service

chkconfig smb on       # Add boot entry

Two 、 edit Samba The configuration file for the service :

Because in Samba In the main configuration file of the service program , There are too many lines of comment information , It's not easy to analyze the important parameters in it , So use the main configuration file first mv Order a change of name , And then use cat Command to read into the main configuration file , And then grep Add after command -v Parameters ( Reverse selection ), Remove all well marks respectively (#) And semicolon (;) The first line of comment information , For the remaining blank lines, you can use ^$ Parameter to represent and filter , Finally, the filtered available parameter information is written into the original file name through redirection . What's left after filtering Samba The parameters of the service program are not complicated , In order to make it easier for readers to check the function of parameters , The following table lists these parameters and the corresponding comments .

mv /etc/samba/smb.conf /etc/samba/smb.conf-backup

cat /etc/samba/smb.conf-backup | grep -v "#" | grep -v ";" | grep -v "^$" > /etc/samba/smb.conf

vim /etc/samba/smb.conf

Samba Parameters and functions in the service program

[global]   # Global parameter .
  workgroup = MYGROUP # Name of working group
  server string = Samba Server Version %v # Server Introduction , Parameters %v To show the SMB Version number
  log file = /var/log/samba/log.%m # Define the location and name of the log file , Parameters %m For the visiting host name
  max log size = 50 # Define the maximum capacity of the log file as 50KB
  security = user # The way of security verification , All in all 4 Kind of
  #share: The visiting host does not need to verify the password ; It's more convenient , But the security is very poor
  #user: You need to verify the password provided by the visiting host before you can access ; Improved security
  #server: Use the independent remote host to verify the password provided by the visiting host ( Centralized management accounts )
  #domain: Use a domain controller for authentication
  passdb backend = tdbsam # Define the type of user background , share 3 Kind of
  #smbpasswd: Use smbpasswd Command to set for system user Samba The password of the service program
  #tdbsam: Create a database file and use pdbedit Command to establish Samba Users of the service program
  #ldapsam: be based on LDAP The service performs account verification
  load printers = yes # Set in the Samba Whether to share the printer device when the service starts
  cups options = raw # Printer options
[homes]   # Shared parameters
  comment = Home Directories # Description information
  browseable = no # Specifies whether the shared information is in “ Online neighbors ” You can see
  writable = yes # Defines whether write operations can be performed , And “read only” contrary
[printers]   # Printer shared parameters
  comment = All Printers  
  path = /var/spool/samba # The actual path to the shared file ( important ).
  browseable = no  
  guest ok = no # Whether everyone can see , Equate to "public" Parameters .
  writable = no  
  printable = yes

3、 ... and 、 Configure shared resources

The first 1 Step : Create account information for accessing shared resources . stay CentOS 6 and 7 In the system ,Samba By default, all service programs use the user password authentication mode (user). This authentication mode ensures that only trusted users with passwords can access shared resources , And the verification process is very simple . however , Only after establishing the account information database , To use the user password authentication mode . in addition ,Samba The database of the service program requires that the account must already exist in the current system , Otherwise, creating a file in the future will lead to confusion of permission properties of the file , This leads to mistakes .

pdbedit Command for management SMB Account information database of service program , The format is “pdbedit [ Options ] Account ”. When writing account information to the database for the first time, you need to use -a Parameters , Change password later 、 This parameter is no longer needed for operations such as deleting accounts .pdbedit The parameters and functions used in the command are shown in the following table .

be used for pdbedit Parameters and functions of the command

Parameters effect
-a user name establish Samba user
-x user name Delete Samba user
-L Make a list of users
-Lv List of user details

useradd samba   # Create an account

pdbedit -a -u samba   # Use it to connect SMB The account information of the service is written into the database

The first 2 Step : Create a file directory for sharing resources . When creating a , We should not only consider the problem of file read and write permissions , And because of /home Directory is the home directory of ordinary users in the system , So you also need to consider the SELinux The limitations of security context . Face up to Samba When filtering annotation information in the server configuration file , Among the filtered information is about SELinux Description of the security context policy , We just need to filter the information about SELinux The value given in the description in the security context policy can be modified . Execute after modification restorecon command , Let's apply the new... To the catalog SELinux The security context takes effect immediately .

mkdir /home/database/

chown -Rf samba:samba /home/database/

restorecon -Rv /home/database

The first 3 Step : Set up SELinux Services and Strategies , Allow it to pass through Samba The service program accesses the home directory of ordinary users . perform getsebool command , Sift out all the links with Samba Service program related SELinux Domain policy , According to the name of the strategy ( And experience ) Select the right policy item to open :

getsebool -a | grep samba

setsebool -P samba_enable_home_dirs on

getsebool -a | grep samba

The first 4 Step : stay Samba In the main configuration file of the service program , Write shared information according to the format mentioned in the table below . In the original configuration file ,[homes] The parameter is the home directory sharing information of the visiting user ,[printers] The parameter is shared printer device . If these two items are not needed in the future work , You can comment it out .

Used for setting up Samba The parameters and functions of the service program

Parameters effect
[database] The share name is database
comment = Do not arbitrarily modify the database file Warn users not to modify the database at will
path = /home/database The shared directory is /home/database
public = no close “ Everyone can see ”
writable = yes Allow write operations

vim /etc/samba/smb.conf

The first 5 Step :Samba The configuration of the service program is basically completed . Next restart smb service (Samba The service is in Linux The name in the system is smb) And configuration iptables A firewall , Let go Samba Four ports for services , Then you can verify the configuration .

service smb restart     # Restart Samba service

service smb status     # see Samba Status of the service

iptables -A INPUT -p tcp --dport 139 -j ACCEPT
iptables -A INPUT -p tcp --dport 445 -j ACCEPT
iptables -A INPUT -p udp --dport 137 -j ACCEPT
iptables -A INPUT -p udp --dport 138 -j ACCEPT

Use iptables By default, the firewall configured by the command will fail when the system is restarted next time , If you want the configured firewall policy to take effect permanently , Execute Save command :

service iptables save

And then there's the Windows Connect under the system Samba Yes , Just in Windows Of “ function ” The command box ( Use shortcut keys “Win+R” You can open it ) Enter two backslashes , Then add the server's IP address .

Enter the new samba Account name and use pdbedit After the password set by the command , You can log in to the shared interface , As shown in the figure below . here , We can try to perform a look 、 write in 、 renamed 、 Delete files and other operations .

This article references from :《Linux It's time to learn 》    Liu Chuang     Writing

CentOS6.5 The structures, Samba Service implementation and Windows More articles about sharing file resources between systems

  1. CentOS6.5 Set up file sharing service under (Samba)

    Samba service : This content is samba Serve learners to provide reference Case description : The administrator of a company needs to build SAMBA The server ,IP Address and allowed access network segment customization .SAMBA The security level of the server is user level , My working group is WORK ...

  2. Centos6 build Samba Service and use Windows mount

    One . Install related software [root@mail ~]# yum install samba samba-client -y # Install related software Two . Configure anonymous access [root@mail ~]# cd /etc/sa ...

  3. CentOS6.5 The structures, FTP service

    One .FTP agreement FTP(File Transfer Protocol, File transfer protocol ) yes TCP/IP One of the protocols in the protocol group .FTP The agreement consists of two parts , One is FTP The server , The second is FTP client . among FT ...

  4. Use Samba Service program , Give Way linux Sharing files between systems

    yum  install -y   cifs-utils mkdir  /database    Create mount directory stay root Home directory create authentication file ( In turn SMB user name .SMB User password .SMB Shared domain )   v ...

  5. Centos6.8 The structures, SVN The server

    1.Centos6.8 The structures, SVN The server Subversion It's a freedom , Open source version control system .Subversion Store the files in the central version library . This version library is very similar to an ordinary file server , The difference is , It can record every ...

  6. be based on LDAP Under the Samba service

    be based on LDAP Under the Samba service One . Environmental conditions : Experimental environment : Two machines , Respectively 2012R2, Installed with AD And as a domain controller Domain Controller(DC), At the same time as DNS Server and time server : ...

  7. [IDS]CentOS6.6 This is based on snort+barnyard2+base Intrusion detection system for , Hyperdetail !!!

    The most detailed CentOS6.6 This is based on snort+barnyard2+base A disclaimer of intrusion detection system based on . If it is lost due to the use of this document ( System crash . Data loss, etc ), The author assumes no responsibility . Two . This document is for personal use only ...

  8. How to be in RHEL7 To build Samba Service implementation Windows And Linux File sharing between

    How to be in RHEL7 To build Samba Service implementation Windows And Linux File sharing between Implement environment :VMware workstations.RHEL7.0 First step : Configure network card IP And yum repositories command :vim ...

  9. Linux Deploy Samba Operation record of service environment

    About Linux and Windows File transfer between systems , Many people choose to use FTP, Relatively safe , But sometimes there are problems , For example, when uploading files , The name of the file is confused , File size change and so on . By comparison , Use Samba As a text ...

Random recommendation

  1. stay docker Run in ASP.NET Core Web API Applications

    This article is an article to guide the rapid drilling , It will be introduced in docker Run a ASP.NET Core Web API The basic steps of the application , In the course of the introduction , It will be right docker Make some simple descriptions of the use of . about .NET Cor ...

  2. python And (re) On regular expressions

    python Regular expression knowledge preparation Regular expressions use backslashes " \ " To represent a special form or as an escape character , Here with Python Grammar conflict of , therefore ,Python use " \\\\ " surface ...

  3. json Judgment fields

    1 Mode one !("key" in obj)  Mode two obj.hasOwnProperty("key")  //obj by json object . 2 Get the value of the indeterminate key for( ...

  4. hadoop Source code interpretation

    http://blog.csdn.net/keda8997110/article/details/8474349

  5. java:jdk Environment variable configuration +tomcat Environment variable configuration

    One :JDK1. Install first jdk  see jdk edition :   DOC The input java -version2. Configure environment variables ( Add system variables )  JAVA_HOME      D:\study\jdk-6\jdk-6(j ...

  6. Linux Communication and synchronization between tasks - summary

    Linux Communication and synchronization between tasks - summary Embedded development communication group 280352802, Welcome to join ! in front , We learned about two ways to achieve multitasking : Processes and threads . Because the process is working in a separate memory space , Different processes cannot directly access to ...

  7. Remove Element,Remove Duplicates from Sorted Array,Remove Duplicates from Sorted Array II

    The following three problems are typical of two pointers dealing with arrays , A pointer is used to traverse , A pointer to the current processing position One :Remove Element Given an array and a value, remove a ...

  8. DataGridView Bind data source

    to DataGridView It's easy to bind data sources , There are two main methods : 1. Bind the data source directly in the control properties , It's the easiest way , But it's directly connected to the database , In this way, he and Zhuan DataTable The consequences are almost the same , So try to avoid it ...

  9. Openstack & Hadoop Combined projects Sahara

    Openstack project Sahara, It's mainly used to build Hadoop colony , Using virtual computing resources , High speed building Hadoop colony . Sahara Project and OPenstack Other project relationships : Picture from :http:// ...

  10. Intellij IDEA Introduction to plug-in development

    Today's IDE Even if " great scourges " As powerful as , But no matter how powerful IDE It can't provide users with all the functions they want , therefore IDE It is generally provided with API Interface for developers to expand . Let's say Intellij IDEA ...