Samba is a file sharing service that implements Windows systems and Linux systems.
a , samba configuration file
The first is to install Samba
[email protected] ~]# Yum install-y Samba samba-client
The Samba configuration file is/etc/samba/smb.conf, and the default annotated section is as follows:
[Email protected] ~]# vim/etc/samba/smb.conf
[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
Note: There are three main parts: [Global], [homes], [printers]
[Global] Defines the global configuration, workgroup is used to define the workgroup, in general, we need to change the mygroup here to Workgroup (Windows default workgroup name).
Security = User
This specifies the security level for 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 use Smbpasswd-a to 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//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//suspend the Samba user account.
Pdbedit-c "[]"-u username//Restore 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:
NetBIOS name = MYSERVER//Set host name that appears in My Network Places
The hosts allow = 127. 192.168.12.192.168.13. Used to set the allowed hosts, if preceded by ";" means all hosts are allowed
Log file =/var/log/samba/%m.log//defines the log for samba, where%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.
Second, samba test
Let's try it out, but before we do the experiment we have to close iptables and selinux, otherwise it is likely that the test will fail.
Experiment One
Requirements: Share a directory, anyone can access, that is, without entering a password to access, require read-only.
1. Open the Samba configuration file
[Email protected] ~]# vim/etc/samba/smb.conf
[Global]//modify the following two places
Workgroup = Workgroup
Server string = Samba Server Version%v
Security = Share
Passdb backend = Tdbsam
Load printers = yes
Cups options = raw
[Tppshare]//Add at the end
Comment = Share all
Path =/tmp/samba
browseable = yes
Public = yes
writable = no
2. Create Test Catalog
[Email protected] ~]# Mkdir/tmp/samba
[Email protected] ~]# chmod 777/tmp/samba
[Email protected] ~]# cd/tmp/samba/
[Email protected] samba]# mkdir 12
[email protected] samba]# Touch test.txt
[Email protected] samba]# echo "1234dfgxc6" > Test.txt
3. Start Samba Service
[[email protected] ~]#/ETC/INIT.D/SMB start
Start the SMB service: [OK]
You can also test whether the smb.conf file is configured correctly with the Testparm command:
[Email protected] ~]# Testparm
4. Testing
(1) test under Windows:
Win+r input \\192.168.0.109 can be seen as shown in the following:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/1B/wKiom1X1FYbCClp7AABO-RRKVJ8582.jpg "style=" float: none; "title=" 1.png "alt=" Wkiom1x1fybcclp7aabo-rrkvj8582.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/18/wKioL1X1F7jybynpAACT6fh-ReU039.jpg "style=" float: none; "title=" 2.png "alt=" Wkiol1x1f7jybynpaact6fh-reu039.jpg "/>
You can try to modify the file, or create a new file, you will find no permissions, only read.
(2) test under Linux:
To install Cifs-utils on the client computer
[email protected] ~]# Yum install-y cifs-utils
Mount to the/opt/directory
[[email protected] ~]# mount-t CIFS//192.168.0.109/tppshare/opt//Do not enter the password directly enter
[Email protected] ~]# df-h
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/1B/wKiom1X1G-HRZM4iAAEYVoSXdjg739.jpg "title=" 3.png " alt= "Wkiom1x1g-hrzm4iaaeyvosxdjg739.jpg"/>[[email protected] ~]# ls-l/opt/
Total Dosage 4
Drwxr-xr-x 2 root root 0 September 13 21:44 12
-rw-r--r--1 root root 11 September 21:29 test.txt
Experiment Two
Requirements: Share a directory, use a user name and password to log in before access, requirements can be read and write.
1. Open the Samba configuration file
[Email protected] ~]# vim/etc/samba/smb.conf
[Global]//modify the following
Workgroup = Workgroup
Server string = Samba Server Version%v
Security = User
Passdb backend = Tdbsam
Load printers = yes
Cups options = raw
[MyShare]//Add at the end
Comment = Share for users
Path =/tmp/mysamba
browseable = yes
public = No
writable = yes
2. Create Test Catalog
[Email protected] ~]# Mkdir/tmp/mysamba
[Email protected] ~]# chmod 777/tmp/mysamba
[Email protected] ~]# cd/tmp/mysamba/
[Email protected] mysamba]# mkdir 111
[[email protected] mysamba]# Touch 1.txt
[Email protected] mysamba]# echo "Dakdfaifhai" > 1.txt
3. Add Users
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
[[email protected] mysamba]# Useradd user1//Create System User
[[email protected] mysamba]# Pdbedit-a user1//Add User1 to Samba account
Note : What are the command parameters of Pdbedit, commonly used is the-L: List of Samba accounts,-x: Delete a Samba account
Restart Samba Services
[[Email protected] mysamba]# service SMB restart
4. Testing
(1) test under Windows:
Win+r input \\192.168.0.109 can see to enter the account password of the prompt box, enter the correct to enter, and then we can modify the folder and file.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/1C/wKiom1X1JtPQ7t2FAABCsGZSWq0516.jpg "title=" 4.png " alt= "Wkiom1x1jtpq7t2faabcsgzswq0516.jpg"/>
Note : From the above we can see that a folder named after the user name is generated because we have not commented out the [home] module.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/1A/wKioL1X1LezgcgFWAADAnNL69NE272.jpg "title=" 8.png " alt= "Wkiol1x1lezgcgfwaadannl69ne272.jpg"/>
After commenting out and restarting the Samba service, we'll see that the User1 directory does not exist.
(2) test under Linux:
[[email protected] ~]# mount-t cifs- o username=user1,password=123456 //192.168.0.109/myshare/opt
[Email protected] ~]# df-h
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/73/1C/wKiom1X1J6ODt1ayAAEWNu3wMN4495.jpg "title=" 5.png " alt= "Wkiom1x1j6odt1ayaaewnu3wmn4495.jpg"/>
View the next
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/1C/wKiom1X1KXPBbd3BAABLPok14iQ351.jpg "title=" 7.png " alt= "Wkiom1x1kxpbbd3baablpok14iq351.jpg"/>
We can do a new file or folder/opt/the directory.
another way to access Linux is to install it on the client Samba-client the package and then access it with the Smbclient command.
[email protected] ~]# Yum install-y samba-client
[Email protected] ~]# smbclient//192.168.0.109/myshare-u user1
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/1C/wKiom1X1KPjSkEo1AAHtQV35lVw769.jpg "title=" 6.png " alt= "Wkiom1x1kpjskeo1aahtqv35lvw769.jpg"/>
SMB also has a lot of commands that you can try.
This article is from the "M April Days" blog, please be sure to keep this source http://1015489314.blog.51cto.com/8637744/1694296
Configure Samba Services