Using Samba to create “shared folder” for Linux (centos7)

Time:2021-5-8

Add Samba service for test server

Samba service is a service for Linux file sharing, which can be understood as “Linux shared folder”. The shared directory can be accessed directly on windows.

For example, to access the home directory of 192.168.1.3, you can directly enter it on the path of the windows file manager\\192.168.1.3\quantum. Of course, if you’re not sure which shared directory to access, you can just type\\192.168.1.3, view all shared directories

|Server IP | Samba account | Samba password|
|192.168.1.3 | Linux account (such as whqt) | 123456|
| | | |
| | | |

The advantage of using Samba is that you can copy logs and edit configuration files directly under windows. You can even use visual studio to open the code project on the server for development directly under windows. Even if the server restarts, it will not cause any impact.

Install and configure Samba service

Install Samba

yum install samba

Configure Samba

Add user and password for Samba

#The user added here must be a Linux user already on the machine
 smbpasswd -a whqt

Start Samba service

Because centos7 adopts strict permission management and access control (IPtable and SELinux), these will affect the operation of samba server. Considering that the server is located in the company intranet and is relatively safe, these services will be banned directly at the startup stage

Centos7 uses chkconfig to manage services

Chkconfig script template

Each service managed by chkconfig needs to add two or more lines of comments to the script

  • Tell chkconfig the run level of the default start and the priority of start and stop. For example:# chkconfig: 2345 55 25
  • Description of service

The service script needs to be implementedstart,stop,restart,statusThe functions of parameters are as follows

case $1 in
    start)    do_start;;
    stop)     do_stop;;
    restart)  do_restart;;
    status)
            echo "Status of $DESC: "
            check_status
            exit "$?"
            ;;
   *)

A complete script

#!/bin/bash
# chkconfig: 2345 55 25
#description: the environment init script
# useage manual
# add to system config
#   chkconfig --add xyd_init.sh
#   chkconfig --level 345 xyd_init.sh on
# start the service
#   service xyd_init.sh start
#   service xyd_init.sh stop
#   service xyd_init.sh restart
#   service xyd_init.sh status

do_start_EX() {
    setenforce 0
    service iptables stop
    service smb restart
    echo "sambda service start success"
}

do_start() {
    do_start_EX
}

do_stop_EX() {
    service smb stop
    echo "sambda servoce stopped"
}

do_stop() {
    do_stop_EX $i
}

do_restart() {
    do_stop
    do_start
}

check_status() {
    echo "do nothing"
}

case $1 in
    start)    do_start;;
    stop)     do_stop;;
    restart)  do_restart;;
    status)
            echo "Status of $DESC: "
            check_status
            exit "$?"
            ;;
   *)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac

Add service to chkconfig

Copy script to/etc/init.d/Directory, and add executable permissionsChmod + X service script

Execute the following command to add the service script to chkconfig for management

Chkconfig -- add service script
Chkconfig -- level 2345 service script on

This completes the configuration of service startup

Manually start chkconfig managed service

It’s like starting any normal service

sudo service xyd_init.sh start

complete

Recommended Today

Looking for frustration 1.0

I believe you have a basic understanding of trust in yesterday’s article. Today we will give a complete introduction to trust. Why choose rust It’s a language that gives everyone the ability to build reliable and efficient software. You can’t write unsafe code here (unsafe block is not in the scope of discussion). Most of […]