Preface
When we use Windows as the client, we usually need to share files and print files. As one of Windows network functions, these requirements can usually be achieved between Windows clients through the features inherent in Windows network. However, with Samba, we can also enable a centos host to be compatible with the Windows Network and achieve the same functionality, so as to make full use of the availability of the centos host.
This document describes how to share files in a Windows Network by building a Samba server.
Install samba
First, install Samba online through yum.
[Root @ sample ~] # Yum-y install Samba plugin install samba
Setting up install process
Setting up Repositories
Update 100% | =================================| 951 B
Base 100% | =================================| 1.1 kb
Addons 100% | =============================| 951 B
Extras 100% | =============================| 1.1 kb
Reading repository metadata in from local files
Primary.xml.gz 100% | =======================| 73 KB
Update: ######################################## ######## 212/212
Added 212 new packages, deleted 0 old in 4.94 seconds
Primary.xml.gz 100% | =======================| 569 KB
Base: ######################################## ######## 1500/1500
Added 1500 new packages, deleted 0 old in 28.97 seconds
Primary.xml.gz 100% | =======================| 157 B
Added 0 new packages, deleted 0 old in 0.03 seconds
Primary.xml.gz 100% | =======================| 32 KB
Extras: ######################################## ######## 124/124
Added 124 new packages, deleted 0 old in 1.93 seconds
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for Samba to pack into transaction set.
Samba-3.0.10-1.4E.9.i386. 100% | ===========================| 101 KB
---> Package Samba. i386. 0.10-1.4e.9 set to be updated
--> Running transaction check
--> Processing dependency: Samba-common =. 0.10 for package: Samba
--> Restarting dependency resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for samba-common to pack into transaction set.
Samba-common-3.0.10-1.4E. 100% | ===========================| 37 KB
---> Package samba-common.i386. 0.10-1.4e.9 set to be updated
--> Running transaction check
Dependencies resolved
========================================================== ============================================
Package arch version repository size
========================================================== ============================================
Installing:
Samba i386 3.0.10-1.4e.9 base 13 m
Installing for dependencies:
Samba-common i386 3.0.10-1.4e.9 base 5.0 m
Transaction Summary
========================================================== ============================================
Install 2 package (s)
Update 0 package (s)
Remove 0 package (s)
Total download size: 18 m
Downloading packages:
(1/2): Samba-common-3.0.1 100% |=========================| 5.0 MB
(2/2): samba-3.0.10-1.4E. 100% | = 13 MB
Warning: rpmts_hdrfromfdno: V3 DSA Signature: nokey, key ID 443e1821
Public Key for samba-common-3.0.10-1.4E.9.i386.rpm Is Not Installed
Retrieving GPG key from http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
Importing GPG key 0x443e1821 "CentOS-4 key <centos-4key@centos.org>"
Key imported successfully
Running transaction Test
Finished transaction Test
Transaction test succeeded
Running transaction
Installing: Samba-common ######################### [1/2]
Installing: Samba ####################### [2/2]
Installed: Samba. i386. 0.10-1.4e.9
Dependency installed: samba-common.i386. 0.10-1.4e.9
Complete!
Configure samba
Then, configure Samba as needed by editing/etc/samba/smb. conf. Here, the principle of this article is to only apply file sharing to the Intranet and give the directory to be shared full read/write permissions.
[Root @ sample ~] # Vi/etc/samba/smb. conf configure edit the samba configuration file
#====================================== Global settings ==================== ======================================
[Global] locate this line (Global Setting label) and add the following lines below this line:
DOS charset = gb2312 character sets the Windows client text encoding to simplified Chinese gb2312
UNIX charset = gb2312 bytes indicates that the code for creating a file or directory on the centos server where Samba is located is gb2312.
Display charset = gb2312 character specifies the default text encoding of the page when SWAT (a tool that controls Samba through a browser) is used.
Directory mask = 0777 catalog specifies the attributes of the new directory (the following four rows)
Force directories mode = 0777
Directory Security mask = 0777
Force Directory Security mode = 0777
Create mask = 0777 objects specifies the attributes of the new file (the following four rows)
Force create mode = 0777
Security mask = 0777
Force security mode = 0777
Workgroup = mygroup groups find this row and change the workgroup name to the workgroup name defined in windows.
Bytes
Workgroup = workgroup worker changes to this State. Here, the default "workgroup" of Windows XP is used as an example.
; Hosts allow = 192.168.1. 192.168.2. 127. Empty find this row, remove the ";" at the beginning of the line, and set access restrictions.
Bytes
Hosts allow = 192.168.0. 127. The access status changes to this status. The intranet IP address and local IP address are specified. Only access in these two cases is allowed.
Enter the following lines at the end of the configuration file to define the public shared directory:
[Public]
Comment = Public stuff
Path =/home/samba folder specify the location of the shared directory
Public = Yes
Writable = Yes others attributes that grant write permission to the shared directory
Next, create a dedicated directory that will be shared to the Windows Network through Samba.
[Root @ sample ~] # Mkdir/home/samba plugin create a dedicated directory for shared files
[Root @ sample ~] # Chown-r nobody./home/samba secrets set the private directory to nobody
[Root @ sample ~] # Chmod 777/home/samba connector set the dedicated Directory attribute to 777
Before connecting to the server, you must set the user used to log on to Samba in advance. Here, we use the samba standard Samba user database management tool "smbpasswd" in centos as an example to create user data for logging on to Samba. Note: The premise of using smbpasswd to create a user is that the user exists in the System user-the information of the user in the samba user database can be created based on the System user.
[Root @ sample ~] # Smbpasswd-A centospub plugin adds the System user centospub (example) to the samba user database
New smb password: Login enter the password used by the user to log on to Samba
Retype new smb password: Confirm again to enter the password
Added user centospub.
Start the samba Service
Before starting the samba service, open the port used by Samba in the firewall settings.
[Root @ sample ~] # Vi/etc/sysconfig/iptables configure edit the iptables configuration file
-A RH-Firewall-1-INPUT-M state -- state new-m tcp-p tcp -- dport 25-J accept rows find this row and add the following lines below:
-A RH-Firewall-1-INPUT-M state -- state new-m tcp-p tcp -- dport 139-J accept
-A RH-Firewall-1-INPUT-M state -- state new-m tcp-p tcp -- dport 445-J accept
-A RH-Firewall-1-INPUT-p udp-m udp -- dport 137-J accept
-A RH-Firewall-1-INPUT-p udp-m udp -- dport 138-J accept
[Root @ sample ~] #/Etc/rc. d/init. d/iptables restart iptables to bring the new rule into effect
Flushing firewall rules: [OK]
Setting chains to policy accept: Filter [OK]
Unloading iptables modules: [OK]
Applying iptables firewall rules: [OK]
Finally, start the samba service.
[Root @ sample ~] # Chkconfig SMB on startup
[Root @ sample ~] # Chkconfig -- list SMB restart confirm the samba startup tag and check that 2-5 is in the on status
SMB 0: off 1: off 2: On 3: On 4: On 5: on 6: Off
[Root @ sample ~] #/Etc/rc. d/init. d/SMB start restart start the samba Service
Starting SMB services: [OK]
Starting nmb services: [OK]
Connect to the Samba server from a Windows Client
After the samba service is started on the server end, we can connect to Samba from a Windows client over a Windows network. Windows XP is used as an example to describe the connection process as follows:
1. Open "Network neighbors" from the desktop and click "view workgroup computers;
2. Confirm the connection to the Samba server and double-click the connection. (The host name in this document is sample)
3. Enter the username and password of the samba user pre-set on the server. (The username is the same as the system username. The password must be the samba-specific password set for the System user through smbpasswd .)
4. Then confirm that you can connect to the Samba server and the root directory and the samba dedicated shared directory appear.
Finally, create, modify, and delete files in the corresponding directory to test the operability of the corresponding permissions.