1. Check whether Samba is installed on CentOS.
# Rpm-qa | grep samba
Note the version number. If the main installation package of samba is missing, you need to download and install the main installation package based on the installed version, or write it in the installed package, and then reinstall it.
Uninstall command: # rpm-e [package name]
Or force uninstall: # rpm-e -- nodeps [package name]
2. Prepare the Installation File
Samba-3.6.9-151.el6.x86_64.rpm
Samba-client-3.6.9-151.el6.x86_64.rpm
Samba-common-3.6.9-151.el6.x86_64.rpm
Samba-winbind-3.6.9-151.el6.x86_64.rpm
Samba-winbind-clients-3.6.9-151.el6.x86_64.rpm
In CentOS, the RPM package can be installed by double-clicking it, and the dependency can be analyzed for ease of installation.
3. After the installation is complete, you can start the samba service.
(1) Start/Close/restart the samba service:
# Sudo/etc/init. d/smb start/stop/restart
Or: # sudo service smb start/stop/restart
(2) view the running status:
# Service smb status
(3) set startup: (automatically run the smb service at levels 3 and 5)
# Sudo chkconfig -- level 35 smb on
4. Enable the firewall port number
1) Port 137 (UDP)-NetBIOS Name Service; nmbd
2) Port 138 (UDP)-NetBIOS datagram Service
3) Port 139 (TCP)-file and print sharing; smbd (based on SMB (Server Message Block) protocol, mainly used in Lan, file sharing protocol)
4) Port 389 (TCP)-used for LDAP (Active Directory Mode)
5) Port 445 (TCP)-NetBIOS service uses this Port in ipvs 2000 and later versions. (Common Internet File System, CIFS, after SMB is extended to the Internet, internet File Sharing)
6) Port 901 (TCP)-used for SWAT, used for webpage management Samba
Enable UDP port: # sudo/sbin/iptables-I INPUT-p udp -- dport xxx-j ACCEPT
Enable TCP port: # sudo/sbin/iptables-I INPUT-p tcp -- dport xxx-j ACCEPT
Save configuration: # service iptables save
5. Configure the shared directory
After logging on to CentOS, create a directory, such as/home/test/shared (test is the user's folder)
Samba configuration file path:/etc/samba/smb. conf
Use vi to edit: # sudo vi/etc/samba/smb. conf
Add at the end of the configuration file:
[Shared]
Path =/home/test/shared
Writeable = yes
Browsable = yes
Valid user = test (here I use the user name for system login)
Save and exit after adding.
Note: Press "A" to start editing. After editing, press "Esc" to exit the editing state and enter ": wq" and press enter to exit. a: Insert, Insert, w: write, q: Exit
Add the test user access permission (or your own system login username ):
# Sudo smbpasswd-a test
6. Disable SELIUNX
In this way, you can add, delete, modify, and view files in the shared directory.
View status:
# Getenforce
Enforcing
Close:
# Sudo setenforce 0
SELIUNX status description:
Enforcing: Forced mode, which indicates that SELinux is running and directory permissions are restricted.
Permissive: the tolerant mode, indicating that SELinux is running, but there is only a warning and there is no actual limit.
Disable: SELinux is not running.
7. Test Access
Test in Linux:
# Smbclient-L // 192.168.101.249-U test
Windows:
Open my computer and enter address LAN:
\ 192.168.101.249
If the password is successfully entered, the system prompts you to enter the user name and password.