Samba server configuration under Centos7 (actual combat)

Samba server configuration under Centos7 (actual combat)

Samba Overview

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

1. Anonymous access to Samba sharing services

1. Install Samba service

[root@localhost ~]# yum install samba -y ##Install Samba service

2. Configure Samba configuration file information

[root@localhost ~]# cd /etc/samba/ ##Switch to the Samba configuration file directory [root@localhost samba]# mv smb.conf smb.conf.bak ##Backup [root@localhost samba]# grep -v "#" smb.conf.bak > smb.conf ##Recreate a configuration file (remove the comments)
[root@localhost samba]# vim smb.conf ##Modify the configuration file [global] ##Global workgroup = SAMBA
        security = user

        passdb backend = tdbsam

        printing = cups
        printcap name = cups
        load printers = yes
        cups options = raw
        map to guest = Bad User ##Add this item to enable anonymous user access##Add the following configuration information to the last line of the big G [myshare] ##Added share file path=/opt/abc ##Path public=yes ##Public access browseable=yes ##Accessible writable=yes ##Write permission create mask=0644 ##Set permissions directory mask=0755

3. Create the myshare path directory and give permissions

[root@localhost samba]# mkdir /opt/abc ##Create directory[root@localhost samba]# chmod 777 /opt/abc ##Give full permissions[root@localhost samba]# systemctl stop firewalld.service ##Turn off the firewall[root@localhost samba]# setenforce 0 ##Turn off enhanced functions[root@localhost samba]# systemctl start smb.service ##Start Samba service

4. Use the test machine to access

Use the test machine to access the share

View Shared Folders

Create a file in the shared folder

View created files in Linux

[root@localhost samba]# cd /opt/abc/ ##View the shared file directory and view the created text [root@localhost abc]# ls
111.txt
[root@localhost abc]# ls -l ##Linux anonymous access user is nobody
Total usage 0
-rw-r--r--. 1 nobody nobody 0 11月5 15:51 111.txt

Second, authentication of Samba sharing service

1. Configure Samba configuration file information

[root@localhost ~]# cd /etc/samba/ ##Switch to the Samba configuration file directory [root@localhost samba]# vim smb.conf ##Modify the configuration file [global]
        workgroup = SAMBA
        security = user

        passdb backend = tdbsam

        printing = cups
        printcap name = cups
        load printers = yes
        cups options = raw ##Delete the anonymous access item ##Add the following configuration information to the last line of the big G [test]
        path=/opt/test ##Shared file directory path browseable=yes ##Can be accessed, remove the public item create mask=0644
        directory mask=0755
        valid users=zhangsan, lisi ##Users allowed to access write list=zhangsan ##Users allowed to write

2. Create smb user

[root@localhost samba]# useradd zhangsan ##Create two users [root@localhost samba]# useradd lisi
[root@localhost samba]# smbpasswd -a zhangsan ##Create smb user and set password New SMB password: ##Set password Retype new SMB password: ##Confirm password Added user zhangsan.
[root@localhost samba]# smbpasswd -a lisi
New SMB password:
Retype new SMB password:
Added user lisi.
[root@localhost samba]# pdbedit -L ##List smb user list zhangsan:1001:
lisi:1002:
[root@localhost samba]# cd /opt/  
[root@localhost opt]# mkdir test ##Create a shared directory [root@localhost opt]# ls
abc rh test
[root@localhost opt]# chmod 777 test/ ##Give maximum permissions [root@localhost opt]# systemctl restart smb.service ##Restart Samba service

3. Use the test machine to access the share

To avoid errors, you can clear the cache on the test first

Use the test machine to access the share

Authentication is required, enter your username and password


Create a file in the test shared folder

View created files in Linux

[root@localhost opt]# cd /opt/test/
[root@localhost test]# ls ##Created successfully 222.txt

4. Since only zhangsan is allowed to write in the configuration file, test whether lisi can write

Accessing shares with lisi

Test Create File

3. Account name mapping for Samba sharing service (account alias login)

1. Configure mapping files and Samba configuration files

[root@localhost ~]# cd /etc/samba/
[root@localhost samba]# vim smbusers ##Create an account mapping configuration file zhangsan = t01 t02 ##Alias ​​t01 t02 password is still the password of user zhangsan [root@localhost samba]# vim smb.conf ##Configure the Samba configuration file [global]
        workgroup = SAMBA
        security = user

        passdb backend = tdbsam

        printing = cups
        printcap name = cups
        load printers = yes
        cups options = raw
        Username map = /etc/samba/smbusers ##Add alias configuration file path [root@localhost samba]# systemctl restart smb.service ##Restart Samba service

2. Use a test machine to test alias access and log in using the alias


Fourth, the access control list of Samba sharing service

1. Configure Samba configuration file information

[root@localhost ~]# cd /etc/samba/ ##Switch to the Samba configuration file directory[root@localhost samba]# vim smb.conf ##Modify the configuration file[test]
  path=/opt/test
  browseable=yes
  create mask=0644
  directory mask=0755
  valid users=zhangsan, lisi
  write list=zhangsan
  hosts deny=192.168.13. ##Add a test to deny access to the 192.168.13 segment
[root@localhost samba]# systemctl restart smb.service ##Restart the Samba service

2. Use the test machine to access the test shared folder

5. Mount the Windows shared folder directly to Linux for use

1. Use Linux to access Windows shared files

[root@localhost ~]# smbclient -L //192.168.100.99/share ##Access the share Enter SAMBA\root's password: ##Password

2. Mount the shared files to Linux and access the files directly

[root@localhost ~]# mkdir -p /opt/share01 ##Create a mount point[root@localhost ~]# mount.cifs //192.168.100.99/share /opt/share01 ##Mount the shared folder to the mount pointPassword for root@//192.168.100.99/share: 
[root@localhost ~]# cd /opt/share01 ##Switch to the mount point [root@localhost share01]# ls
test.txt
[root@localhost share01]# cat test.txt ##View the file contents of the shared folder this is a test!!

(For Windows specific sharing settings, please refer to the previous blog, thank you!!)

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • A brief analysis of how to build a samba server on Centos7

<<:  MySQL 8.0.11 installation and configuration method graphic tutorial (win10)

>>:  MySQL 8.0.15 compressed version installation graphic tutorial

Recommend

Implementation of adding remark information to mysql

Preface Some people have asked me some MySQL note...

Detailed installation tutorial of Docker under CentOS

Docker is divided into CE and EE. The CE version ...

How to install and configure mysql 5.7.19 under centos6.5

The detailed steps for installing mysql5.7.19 on ...

How to use the jquery editor plugin tinyMCE

Modify the simplified file size and download the ...

Node.js implements breakpoint resume

Table of contents Solution Analysis slice Resume ...

Detailed tutorial on installing the jenkins container in a docker environment

Recommended Docker learning materials: https://ww...

MySQL 5.7.17 installation and configuration graphic tutorial

The blogger said : I have been writing a series o...

Nodejs combined with Socket.IO to realize websocket instant communication

Table of contents Why use websocket Socket.io Ope...

How to set the text in the select drop-down menu to scroll left and right

I want to use the marquee tag to set the font scro...

vue $set implements assignment of values ​​to array collection objects

Vue $set array collection object assignment In th...

Implementation of rewrite jump in nginx

1. New and old domain name jump Application scena...

Teach you how to achieve vertical centering elegantly (recommended)

Preface There are many ways to center horizontall...

HTML meta usage examples

Example Usage Copy code The code is as follows: &l...

Native JS music player

This article example shares the specific code of ...

Six inheritance methods in JS and their advantages and disadvantages

Table of contents Preface Prototype chain inherit...