Install and configure Samba in CentOS7

Source: Internet
Author: User

Install and configure Samba in CentOS7

I. Samba Introduction

Samba is a free software that implements the SMB protocol on Linux and UNIX systems. It consists of servers and client programs. Server Messages Block (SMB) is a communication protocol used to share files and printers on a LAN, it provides sharing services for files, printers, and other resources between different computers in the LAN. The SMB protocol is a client/server protocol that allows a client to access shared file systems, printers, and other resources on the server. By setting "NetBIOS over TCP/IP", Samba can not only share resources with local network hosts, but also share resources with computers around the world.

Samba can be used for file sharing and print sharing between Linux and windows systems. Samba can be used for file sharing between windows and Linux, it can also be used for sharing resources between Linux and Linux.

Ii. Disable SELinux and Firewall

A. temporarily shut down (no need to restart the machine ):

# Setenforce0 # Set SELinux to permissive mode (disable SELinux) # Setenforce1 # Set SELinux to enforcing mode (enable SELinux)

B. To modify the configuration file, restart the machine:

#vi/etc/selinux/config

Change SELINUX = enforcing to SELINUX = disabled (The machine needs to be restarted)

C. You can make your own policy to open the corresponding port. Here I close it directly:

# Systemctlstatusfirewalld. service # view the Firewall Status # Systemctlstopfirewalld. service # disable Firewall

3. Install the Samba Service

① Install yum directly

#yuminstallsambasamba-client

② Start and view Samba

# Systemctlstartsmbnmb # Note: NMB provides NetBIOS services for clients #systemctlstatussmbnmb

4. Configure the Samba Service

① Configuration

#vi/etc/samba/smb.conf =========================== GlobalSettings [Global Options] ========================== ==================== [global] # workgroup=WORKGROUP # Set the workgroup or domain to which SambaServer belongs serverstring=SambaServerVersion% v # Set the annotation. Macro % v indicates that the Samba version is displayed. netbiosname=zhi # Set the NetBIOS Name of SambaServer maptoguest=baduser # Enable Anonymous Access # --------------- LoggingOptions [log options] ----------------------------- log file = /var/log/samba/log .%m # Set the storage location and name of the log file. The macro % m (host name) indicates that a log file is recorded separately for each machine accessing the SambaServer. maxlogsize=50 # Set the maximum size of the SambaServer log file, in KB. 0 indicates no limit # ---------------- StandaloneServerOptions [run processes independently] ------------------- security=share # Sharing Level: shared directories can only be accessed by authorized users passdbbackend=tdbsam # Create a security account management database # ----------------- PrintingOptions [Print Options] ----------------------------- # Loadprinters = yes # Set whether to share a printer when Samba is started # Cupsoptions = raw # General unix print options #========================== Define Definitions [sharing parameters] ======================= ==================== [homes] # Set the user's home directory comment=HomeDirectories # Description of the share: Home Directory browseable=no # Specify whether the share can be viewed writable= yes # Specify whether the shared path is writable [printers] # Set the printer's home directory comment=AllPrinters # Description: All printers path= /var/spool/samba browseable=no guestok=no # Specify whether the share allows access by the guest account writable=no printable= yes # Specify whether to print [public] comment=PublicStuff # Definition description path= /home/samba # Shared directory path public= yes # Specify whether the share allows access by the guest account writable= yes printable=no writelist=+staff # Users allowed to write data to the share

Note:

+ =====" Search only in the password file group of the Local Machine & =====" Is only available in the nis Service @ =====" Search through the NIS server first, and find it on the local machine after nis cannot be found

② Test syntax

③ Create a shared directory

#mkdir/home/samba #cd/home/samba/ #touchsamba.txt

V. Test

① Access through \ 192.168.10.128 in windows

② Input smbclient // 192.168.10.128/public access in Linux

③ Configuration only allows access by individual users

A. Configure smb. conf and add the following

[ time ] comment=AshesOfTime path= /share/time valid users =zhi writelist=zhi printable=no createmask=0755 directorymask=0755

B. Create a shared directory and add users and groups.

#mkdir-p/share/time #groupaddadmin #useraddzhi-s/sbin/nologin #cd/share/time #echo"12345">abc.txt # Pdbedit-a-uzhi # create a Samba user

# Pdbedit-L # view the Samba user list # Systemctlrestartsmbnmb # restart Samba

Note: You can use the command smbpasswd-a + User Name to add a Samba password for this user, but the user must be a system user.

C. Verification

Windows client Verification:

Right-click this computer and select ing network drive"

Prompt for username and password

After entering

It will be displayed on this computer

Error: Enter the user name and password and the following content will pop up:

"The specified network folder is currently mapped using another user name and password. Use another user name and password to connect. First, disconnect all existing mappings to network sharing ."

Solution: run the net use command to view

Run the net use */delete command to end all connections.

Linux client Verification:

$smbclient-L192.168.10.128-Uzhi

$smbclient //192 .168.10.128 /time -Uzhi

Problem: Unable to upload after downloading

Solution:

# Setfacl-mu: zhi: rwx/share/time/# grant the User Write Permission

You can upload the file.

Linux mounting

$ sudo apt-get install cifs-utils # Network file sharing system suite $ sudo mkdir /mnt/samba $ sudo mount -tcifs //192 .168.10.128 /time /mnt/samba -ousername=zhi

Automatic mounting in Linux

$ sudo vi /etc/fstab # Add the following //192 .168.10.128 /time /mnt/samba cifscredentials= /etc/samba/zhi . passwd 00 $ sudo vi /etc/samba/zhi . passwd # Prevent password leakage, so create another file username=zhi password=abcdef $ sudo chmod og=--- /etc/samba/zhi . passwd # Set the Password File Permission $ sudo umount /mnt/samba # Uninstall $ sudo mount -a # Mount all options under fstab $ ls /mnt/samba/

Attachment: wiki for installing and configuring Samba in Ubuntu:

Http://wiki.ubuntu.org.cn/Samba

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.