Before I shared files on Windows, just right-click the folder you want to share and choose share related options settings. But how do you implement file sharing for Windows and Linux? This involves the Samba service, which is not difficult to configure and very simple to use.
Samba configuration file smb.conf
When installing the system, Samba is installed by default, and if it is not installed, you only need to run this command to install it on CentOS:
Yum Install-y Samba Samba-client
samba's configuration file is/etc/samba/smb.conf, by modifying this configuration file to complete our various needs. Open this configuration file, you will find a lot of content with looked away. Let's take a look at the parts that are not commented out:
[global] workgroup = mygroup server string = Samba Server Version %v 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
There are three main parts: [Global], [homes], [printers]
[Global] Defines the global configuration, workgroup is used to define the workgroup, and I believe that if you install a Windows system, you will not be unfamiliar with this workgroup. In general, we need to change the mygroup here to Workgroup (the Windows default workgroup name).
Security = User #这里指定samba的安全等级. There are four types of safety levels:
Share: Users do not need an account and password to log in to the Samba server
User: The Samba server providing the service checks the account and password (default)
Server: Checking account and password work is done by another Windows or Samba server
Domain: Specifies the Windows domain control server to verify the user's account and password.
Passdb backend = Tdbsam # Passdb backend (user backend), Samba has three user backgrounds: smbpasswd, Tdbsam, and Ldapsam.
SMBPASSWD: This method uses the SMB tool SMBPASSWD to set up a samba password for the system user (real or virtual), which the client uses to access the Samba resources. SMBPASSWD in/etc/samba, it is sometimes necessary to create the file manually.
Tdbsam: Create a user database with a database file. The database file is called Passdb.tdb, in/etc/samba. The PASSDB.TDB user database can be used to smbpasswd -a create samba users, and Samba users to create must first be system users. You can also use Pdbedit to create a samba account. Pdbedit a number of parameters, listed several main:
PDBEDIT-A Username: Create a new samba account.
Pdbedit-x Username: Delete Samba account.
Pdbedit-l: Lists the list of Samba users and reads the PASSDB.TDB database file.
PDBEDIT-LV: Lists the Samba user list details.
Pdbedit-c "[D]"-u username: Pauses the Samba user account.
Pdbedit-c "[]"-u username: Restores the samba user account.
Ldapsam: Authenticates the user based on the LDAP account management method. First to establish the LDAP Service, set "Passdb backend = Ldapsam:ldap://ldap Server"
The Load printers and cups options two parameters are used to set up printer-related.
In addition to these parameters, there are several parameters you need to know:
NetBIOS name = MYSERVER # Sets the host name that appears in My Network Places
The hosts allow = 127. 192.168.12.192.168.13. # used to set allowed hosts, if preceded by ";" means all hosts are allowed
Log file =/var/log/samba/%m.log #定义samba的日志, where the%m is the NetBIOS name above
Max log size = 50 # Specifies the maximum capacity of the log, in K
[Homes] This part of the content share the user's own home directory, that is, when the user logged on to the samba server is actually entered into the user's home directory, after the user login, the share name is not homes but the user's own identifier, for a simple file-sharing environment, this part can be looked out.
[Printers] This part of the content set up printer sharing.
Samba Practice
Note: Before testing, please check if SELinux is off or it may not be successful. For more information on how to turn off SELinux, see the 16th Linux Firewall section of Linux System Management.
1. Share a directory, anyone can access, that is, without entering a password to access, require read-only
Open the configuration file for Samba/etc/samba/smb.conf in the [Global] section
Put
MyGroup
Change to:
WORKGROUP
Put
Security = User
Modified to:
Security = Share
Then add the following at the very end of the file:
[share] comment = share all path =/tmp/samba Browseable = yes public = yes writable = No
To create a test catalog:
Mkdir/tmp/sambachmod 777/tmp/sambatouch/tmp/samba/sharefilesecho "111111" >/tmp/samba/sharefiles
To start the Samba service:
/ETC/INIT.D/SMB start
Test:
First Test that you configured the smb.conf is correct, with the following command:
Testparm
You should see a warning: warning:the security=share option is deprecated, but the impact is small, no need to control it. If there is no error, enter it in the browser on your Windows machine:
File://IP/share
See if you can access the Sharefiles
2. Share a directory, log in with a user name and password to access, request can read and write
Open the configuration file for Samba/etc/samba/smb.conf
The [Global] section reads as follows:
[Global] Workgroup = Workgroup Server string = Samba Server Version%v security = user Passdb backend = Tdbsam load printers = yes cups options = raw
You will also need to include the following:
[MyShare] comment = Share for users path =/samba browseable = yes writable = yes Publi c = No
To save the configuration file, create the directory:
Mkdir/sambachmod 777/samba
Then add the user. Because in [Globa] "Passdb backend = Tdbsam", to use pdbedit to increase the user, note that the added user must exist in the system, so you need to create a system account:
Useradd User1useradd User2
Then add User1 to the Samba account:
Pdbedit-a user1
Add User2 to your Samba account:
Pdbedit-a User2
We can list all Samba accounts:
Pdbedit-l
To restart the Samba service:
Service SMB Restart
Test:
Open IE Browser input:
File://IP/myshare/
Then enter your user name and password
3. Accessing the Samba server using Linux
Samba services are also accessible under Linux. The premise is that your Linux installed the Samba-client package. After installation, you can use the Smbclient command. The specific syntax is:
Smbclient//ip/share name-u user name
Such as:
[Email protected]]# smbclient//10.0.4.67/myshare/-u user1password:domain=[workgroup] Os=[unix] Server=[Samba 3.6.9-151.EL6]SMB: \>
The interface appears as shown above. You can make a "?" List of all the commands you can use. Commonly used CDs, LS, RM, pwd, tar, mkdir, chown, get, put, etc., use help + commands to print how the command is used, where get is downloaded and put is uploaded.
The other way is to mount it via mount, such as:
Mount-t CIFS//10.0.4.67/myshare/mnt-o username=user1,password=123456
The format is like this, to specify that -t cifs //IP/共享名 本地挂载点 after-O with username and password after the load can be used as a local directory to use the shared directory, note that the share name can not be followed by a slash.
Configuring the Samba server