The Linux file service Samba

Source: Internet
Author: User

1. Samba

Samba Services

Samba is a free software that implements the SMB protocol on Linux and UNIX systems, consisting of servers and client programs. SMB(Server Messages block, information service blocks) is aLANshared files and printers on aCommunication Protocols, it provides shared services for files and printers among different computers within the LAN. The SMB protocol is a client/server protocol that allows clients to access shared file systems, printers, and other resources on the server. By setting up "NetBIOS over TCP/IP", Samba will not only share resources with local network hosts, but also share resources with computers around the world.


Role: Shared directory (SMB protocol)

Software: Samba server, samba-client client

Configuration file:/etc/samba/smb.conf

Services: SMB, NMB

Ports: SMB---> 139/tcp, 445/TCP provides file sharing capabilities

NMB---> 137/udp, 138/udp provides a computer name to parse

Configuration file:/etc/samba/smb.conf


Global configuration


[Global]

Workgroup = MyGroup>>> set workgroup name

Server string = Samba Server version%v>>> Show Samba software release information


Interfaces = Lo eth0 192.168.12.2/24 192.168.13.2/24>>>samba service listening IP address


The hosts allow = 127. 192.168.12.192.168.13. >>> set only which hosts are allowed to access

Hosts Deny = 192.168.12. 192.168.1.1/24>>> deny which hosts are accessible

Security = user>>> Authentication-based access

Share>>> Anonymous Access

Shared directory Configuration


[Share name]

Comment = >>> description Information

Path =/BJ>>> Specify directory Name

browseable = yes >>> downloadable files

writable = yes >>> can upload files

Public = yes >>> allow all users access

Write list = User1>>> allow only user1 to upload files


Example:


Environment Description:

Linux 192.168.122.105Centos 7.2 file Sharing Server

Windows/linux Client

Demand:

The local/caiwu directory is shared via the Samba software, and the client can access it via the Martin user, allowing it to download files only

1) Turn off SELinux, firewall


[Email protected] ~]# Setenforce 0

[Email protected] ~]# Getenforce

Permissive

[Email protected] ~]# Vim/etc/sysconfig/selinux


[Email protected] ~]# Systemctl stop Firewalld.service

[Email protected] ~]# systemctl disable Firewalld.service

2) Install the software


[email protected] ~]# Yum install-y Samba samba-client

3) Edit the configuration file, share the/caiwu directory


[Email protected] ~]# Mkdir/caiwu

[Email protected] ~]# Touch/caiwu/{1..5}.mp3

[Email protected] ~]# vim/etc/samba/smb.conf

[Caiwu]

Comment = It is a test

Path =/caiwu

browseable = yes


4) Create a shared user


[Email protected] ~]# Useradd Martin

[Email protected] ~]# smbpasswd-a Martin

New SMB Password:

Retype new SMB Password:

Added user Martin.


[[email protected] ~]# pdbedit-l>>> View shared users

MARTIN:1001:

[Email protected] ~]#



5) Start the service


[[email protected] ~]# systemctl start SMB

[[email protected] ~]# Systemctl enable SMB

[Email protected] ~]# SS-ANTP | grep SMBD

LISTEN 0 *:139 *:* Users: (("SMBD", pid=2804,fd=38))

LISTEN 0 *:445 *:* Users: (("SMBD", pid=2804,fd=37))

LISTEN 0::: 139:::* Users: (("SMBD", pid=2804,fd=36))

LISTEN 0::: 445:::* Users: (("SMBD", pid=2804,fd=35))

6) Test Access


Windows client:


\\192.168.122.105


To cancel the sharing of a user's host directory

[Email protected] ~]# vim/etc/samba/smb.conf


#[homes]

# comment = Home directories

# browseable = No

# writable = yes


[[email protected] ~]# systemctl restart SMB

Linux client:


[email protected] ~]# Yum install-y samba-client


[Email protected] ~]# smbclient//192.168.122.105/caiwu-u Martin

Configuration allows Martin users to upload files


1) Edit the configuration file


[Email protected] ~]# vim/etc/samba/smb.conf

[Caiwu]

...

writable = yes

[[email protected] ~]# systemctl restart SMB


2) Set local permissions on the directory


[Email protected] ~]# setfacl-m u:martin:rwx/caiwu/

Example:


Share the local/shichang directory via Samba software, allowing Martin users to download files and allow admin users to upload files

1) Create a directory, create a shared user


[Email protected] ~]# Mkdir/shichang

[Email protected] ~]# touch/shichang/{1..5}.jpg

[Email protected] ~]#

[[email protected] ~]# Useradd admin

[[email protected] ~]# smbpasswd-a admin

New SMB Password:

Retype new SMB Password:

Added user admin.

[Email protected] ~]#

[Email protected] ~]# pdbedit-l

MARTIN:1001:

ADMIN:1002:

[Email protected] ~]#



2) Edit the configuration file


[Email protected] ~]# vim/etc/samba/smb.conf


[Shichang]

Path =/shichang

browseable = yes

Write list = admin


[[email protected] ~]# systemctl restart SMB


[Email protected] ~]# chown admin/shichang/

[Email protected] ~]# ls-ldh/shichang/

Drwxr-xr-x. 2 Admin Root 66 February 12:00/shichang/

[Email protected] ~]#

3) test access


Clear the shared cache for Windows

NET use */del

Windows Settings network mapped drive access share


This article is from the "lyw666" blog, make sure to keep this source http://lyw666.blog.51cto.com/12823216/1957466

The Linux file service 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.