Install and configure the Samba service in CentOS 6.4

Source: Internet
Author: User
Tags server installation and configuration

Install and configure the Samba service in CentOS 6.4
0. environment Description samba Server System: CentOS 6.4 x86_64samba Server IP: 192.168.4.211samba Client System: CentOS 6.4 x86_64samba Client IP: 192.168.4.212 1. install Step-1 on the samba server: Open the corresponding port on the firewall for samba and run the following command:

Iptables-I INPUT-p tcp -- dport 137-j ACCEPT
Iptables-I INPUT-p udp -- dport 137-j ACCEPT
Iptables-I INPUT-p tcp -- dport 138-j ACCEPT
Iptables-I INPUT-p udp -- dport 138-j ACCEPT
Iptables-I INPUT-p tcp -- dport 139-j ACCEPT
Iptables-I INPUT-p udp -- dport 139-j ACCEPT
Iptables-I INPUT-p tcp -- dport 445-j ACCEPT
Iptables-I INPUT-p udp -- dport 445-j ACCEPT
Service iptables save
Service iptables restart
Step 2: Set SELinux to permissive mode and run the following command:
Setenforce 0
Vi/etc/selinux/config

Replace
SELINUX = enforcing with SELINUX = permissive
Step 3: Install the samba server and run the following command:
Yum install-y samba
Step-4: configure the smb. conf file and run the following command:
Mv/etc/samba/smb. conf/etc/samba/smb. conf. bak
Vi/etc/samba/smb. conf

The configuration file is as follows:

[Global]
# The Working Group of the samba server is WORKGROUP workgroup = WORKGROUP.

# Samba server description Server string = Samba server Version % v

# NetBIOS name of the samba Server netbios name = CentOS. Server

# Client access log file of the samba server =/var/log/samba/log. % m

# The maximum log size is 50 KB max log size = 50

# Use tdbsam to store user information passdb backend = tdbsam

# Use user authentication to ensure security
Security = user

# Ing anonymous user access
Map to guest = bad user
Guest account = nobody

[Homes]
# Shared directory description
Comment = Home Directories

# Valid user, valid users = % S in the/home Directory

# Browseable = No in Windows Network Sharing

# Writable = Yes in this directory

[Private]
# Shared directory description
Comment = Demo Directory

# Shared directory path
Path =/samba/private

# Valid users
Valid users = @ user1

# View this directory in Windows Network Sharing
Browseable = Yes

# This directory cannot be publicly Accessed Anonymously
Public = No

# This directory is writable
Writable = Yes

[Public]
# Shared directory description
Comment = Public Stuff

# Shared directory path
Path =/samba/public

# View the directory browseable = Yes in Windows Network Sharing

# This directory can be publicly Accessed Anonymously
Public = Yes

# This directory is writable
Writable = Yes
Step 5: create two user groups and users in the system: user1 and user2. Run the following command:
Groupadd user1
Useradd-g user1 user1
Passwd user1
Groupadd user2
Useradd-g user2 user2
Passwd user2

Note: The passwords of user1 and user2 are both passwords.
Step 6: create two users on the samba server and run the following command:
Smbpasswd-a user1
Smbpasswd-a user2

Note: The samba password for user1 and user2 is password.
Step-7: create a directory and set access permissions. Run the following command:
Mkdir-p/samba/public
Mkdir-p/samba/privatechmod-R 777/samba
Step-8: Configure and start the samba service and run the following command:
Chkconfig smb on
Chkconfig nmb on
Service smb start
Service nmb start
By configuring the above eight steps, you can access the shared directory on the client. Both user1 and user2 can access the public directory with read and write permissions. Only user1 can access the private directory with read and write permissions. The personal directories of user1 and user2 are invisible and can only be accessed through URLs, both have read and write permissions. 2. Install the samba client Step 1: Install the samba client and run the following command:
Yum install-y samba-client
Step 2: connect to the shared directory on the server and run the following command:
# Connect to the public directory
Smbclient // 192.168.4.211/public-U user1

# Connect to a personal directory
Smbclient // 192.168.4.211/user1-U user1 if the logon is successful, the Shell command will be changed to the following prompt: smb: \>
Step-3: disconnect and run the following command in the samba command line:
Quit
The above three steps allow the samba client to use samba for sharing. 3. Manually mount the samba shared directory Step-1: mount the user1 personal directory to the/samba directory of the samba client and run the following command:
Mkdir-p/samba
Mount-t cifs // 192.168.4.211/user1/samba-o user = user1, password = password, workgroup = WORKGROUP
Step 2: After the personal directory is used up, uninstall the mount and run the following command:
Umount/samba
4. automatically mount the samba shared directory at startup by adding a shared directory Mount entry to the fstab file to enable automatic mounting at startup. However, the connection to the samba server will remain active. Run the following command:
Mkdir/samba
Vi/etc/fstab

Add a mount entry to the shared directory at the end of the above file, as shown below:
// 192.168.4.211/user1/samba cifs ults, username = user1, password = password 0 0

The value 0 indicates that the file system in the shared directory does not need to use the dump command for dump, the value 0 indicates that the file system in the shared directory does not need to use The fsck command for checking.
In addition, you can also use the automatic mounting tool (autofs) to automatically mount the network shared directory as needed. When the shared file is no longer in use and is not active for a certain period of time, the auto-mounting device unmounts the shared file. 5. automatically mount the samba shared directory as needed Step-1: Modify the time-out period of the inactive state and run the following command:
Vi/etc/sysconfig/autofs

Replace
TIMEOUT = 300
Replace
TIMEOUT = 600
That is, the time-out period of the inactive state is changed from 5 minutes to 10 minutes.
Step 2: Create the parent directory of the shared directory mount point and run the following command:
Mkdir-p/samba
Step-3: configure the parent directory of the shared directory mount point and run the following command:
Vi/etc/auto. master

Add a line at the end of the above file, as shown below:
/Samba/etc/auto. samba

/Samba is the parent directory of the mount point, which is always visible in the system and monitored by the autofs service to determine whether a sub-directory mount point is required. /Etc/auto. samba is a single configuration file that contains a list of sub-directory mount points managed by the autofs service in this parent directory.
Step 4: configure the shared directory mount point directory and run the following command:
Vi/etc/auto. samba

The content of the above file is as follows: user1-fstype = cifs, username = user1, password = password: // 192.168.4.211/user1

Here, user1 is a sub-directory mount point, which is usually invisible. it is visible only when the autofs service directly names and accesses the directory after it is created and shared.
Step 5: restart the autofs service and run the following command:
Service autofs restart
Step 6: Access the shared network directory and run the following command:
Cd/samba/user1

After running the preceding command, autofs automatically creates a mount point directory and mounts the shared directory.
Step-7: unmount the network shared directory. The details are as follows:
Autofs uninstalls the shared directory after all files and directories under/samba/user1 are out of use and expire (10 minutes.

------------------------------------ Split line ------------------------------------

How to share files with Samba in Ubuntu 14.04

The speed of accessing samba from Ubuntu dual Nic of VMWare Virtual Machine doubles

Add the Samba File Sharing Server to the Windows Server 2003 Domain

Samba installation Configuration

Samba service configuration in CentOS 6.2

Samba Server installation and configuration

How to Build the Win7 + VMware + Fedora18 Samba Server

------------------------------------ Split line ------------------------------------

Samba details: click here
Samba: click here

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.