Using Samba for file sharing between Linux and Windows

Source: Internet
Author: User

Samba

Samba is a free software that allows the Linux family of operating systems to be linked to the smb/cifs (Server Message block/common Internet File System) network protocol of the Windows operating system. The biggest feature is the ability to use file sharing and print sharing directly with Linux and Windows systems (the resource share between Linux and Linux is more NFS-enabled).
There are two services that make up samba, one is SMB and the other is NetBIOS. SMB is the core startup service for Samba, primarily responsible for establishing a dialog between Samba servers and Samba clients, authenticating users and providing access to file and print systems, listening to 139 TCP ports (enhanced SMB Protocol CIFS Direct listening 445 port, CIFS does not require a NetBIOS protocol), while the NetBIOS service is responsible for parsing, providing a list of shared resources on the browse network, listening on UDP ports 137 and 138.

Implementing Samba
    • To install Samba:
[Email protected] ~]# lsb_release-rrelease:    yum-y Install samba[[email protected] ~]# Rpm-qi Sambaname
   : Sambaepoch       : 0Version     : 4.7.1Release:     6.el7~]# systemctl stop firewalld.service[[ Email protected] ~]# Setenforce 0
    • Samba-related configurations:
Master configuration file:/etc/samba/smb.conf Main program: NMBD (NetBIOS Name Server Daemon), SMBD (SMB/CIFS Daemon) Unit files: Smb.service and Nmb.service
Which/etc/samba/smb.conf file Common parameters: Global configuration: [Global] workgroup=mygroup #工作组名 server String=samba server Version%v #服务器信息介绍 NetBIOS Name=myserver #用netbios名来指定服务 Interfaces=[interface1 interface2...| Address1 Address2 ...] #用于让samba服务监听多个网络接口或IP hosts Allow=[address1 Address2 ...] #指定允许访问的主机IP log file=/var/log/samba/log.%m #指定日志存放路径,%m is the visiting host name Max log size=50 #定义日志文件最大容量为50K Security=user #设置samba服务的安全认证方式为user passdb Backend=tdbsam #定义用户后台的类型为tdbsam, other types are smbpasswd, Ldapsam load Prints=yes #设置是否共享打印机  Cups Options=raw #打印机选项 Other configurations: [Homes]: Define for each samba user whether they can access their home directory through the Samba service [printers]: Define the Print Service [custom shared directory]: Define shared file systems Common directives: comment=string: Note path=/path/to/filename: The file system path mapped by the current share browseable=yes: Whether it is browsable, whether it can be viewed by all users pulibc= YES: Allow anonymous access to Browseable=no: whether to expose directory Writable=yes: write read only=no|yes: read-only write list=/path/to/user_list| USERNAME: List of users with write permissions
Directory Mask=mask: Permission values for new directory
Create Mask=mask: New file's permission value more parameters can be obtained by commandMans smb.confView.
    • Custom Shared Directories:
[Email protected] ~]# vim/etc/samba/smb.conf[Shared_dir]        comment=shared dir through Samba Path=/samba_dir writable=yes[[email protected] ~]# mkdir/samba_dir  testparm  #校验/ etc/samba/smb.conf file is configured correctly load SMB config files from/etc/samba/smb.confrlimit_max:increasing Rlimit_max (1024x768) to Minimum Windows limit (16384) Processing section "[Homes]" processing sections "[Printers]" Processing section "[print$]" Processing section "[Shared_dir]" Loaded Services file OK. Server Role:role_standalone
    • The Samba service default authentication mode is user, so you need to create a samba user database:
The Samba account must be present on the Linux system (/ETC/PASSWD) and its password needs to be maintained separately. There are special commands for creating a Samba user database: Pdbedit and SMBPASSWD.  pdbedit [options] account options:-A   USERNAME: Create Samba User-   x: Delete Samba user-    L: Lists the list of Samba users 
   -lv: Listing user Details list smbpasswd [options] USERNAME options:-A  : Add Account-   x: Delete Account-  D: Disable account -  E: Enable account [[email protected] ~]# useradd samba_user1[[email protected] ~]# pdbedit-a samba_user1new Password: Retype new Password:unix Username:        samba_user1[[email protected] ~]# useradd samba_user2[[email protected] ~]# Smbpasswd-a samba_user2new SMB password:retype new SMB password:added user Samba_user2.        
    • Windows Host test:
~~]# systemctl start Nmb.service
# Client Test
    • As you can see, the user cannot create a directory under/samba_dir after logging in, and Writable=yes has already been set. This is because the owners and genera of the/samba_dir directory are root and other users do not have write permissions. Make the following changes:
[[Email protected] ~~]# usermod-g samba samba_user1[[email protected] ~]# usermod-g Samba Samba_user2[[email PR Otected] ~]# ID samba_user1uid=1005 (samba_user1) gid=1005 (samba_user1) groups=1005 (Samba_user1), 1007 (samba) [email Protected] ~]# ID samba_user2uid=1006 (samba_user2) gid=1006 (samba_user2) groups=1006 (Samba_user2), 1007 (samba) [[ Email protected] ~]# ll-d/samba_dirdrwxr-xr-x. 2 root root 6 June 17:19/samba_dir[[email protected] ~]# chown:samba/samba_dir[[email protected] ~]# chmod G+w/samba _dir[[email protected] ~]# ll-d/samba_dirdrwxrwxr-x. 2 Root Samba 6 June 17:19/samba_dir
    • Windows host re-test:

Linux hosts to test:

# mount Access. Note that the name that is accessed here is /shared_dir, which is defined by [] in configuration file/etc/samba/smb.conf. [[Email protected]~]#mount-t cifs//192.168.4.119/shared_dir/mnt-o username=samba_user1Password for [email protected]//192.168.4.119/shared_dir: ******[[email protected] ~]# ls/mnthello.txt Test[[email protected] ~]# touch/mnt/hello[[email protected] ~]# ls/mnthello hello.txt test# using Smbclient Client Access [[email protected] ~]# yum install-y samba-client[[email protected] ~]# smbclient//192.168.4.119/shared_  Dir-u samba_user2 #交互式访问Enter samba\samba_user2 ' s password:try "help" to get a list of possible COMMANDS.SMB: \> ls                                   .                                 D 0 Tue Jul 3 17:07:35 2018..                            DR 0 Fri June 17:19:56 2018 Test D 0 Tue Jul 3 15:42:01 2018 Hello.txt  A 0 Tue Jul 3 17:07:31 2018 Hello N 0 Tue Jul 3 17:07:35 2018 121055488 blocks of size 1024. 116173648 blocks AVAILABLESMB: \> [[email protected] ~]# smbclient-l//192.168.4.119/shared_dir-u Samba_uSer1 #查看共享情况Enter samba\samba_user1 ' s password:sharename Type Comment------------------- -print$ disk Printer Drivers shared_dir disk shared dir through samba ipc$ IP C IPC Service (Samba 4.7.1) samba_user1 Disk Home directoriesreconnecting with SMB1 for workgroup Listin G. Server CommenT---------            -------Workgroup Master---------            -------SAMBA Happiness WORKGROUP DESKTOP-l064dv0

Using Samba for file sharing between Linux and Windows

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.