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


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, you can directly enter it on the path of the windows file manager\\\quantum. Of course, if you’re not sure which shared directory to access, you can just type\\, view all shared directories

|Server IP | Samba account | Samba password|
| | 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;;
            echo "Status of $DESC: "
            exit "$?"

A complete script

# chkconfig: 2345 55 25
#description: the environment init script
# useage manual
# add to system config
#   chkconfig --add
#   chkconfig --level 345 on
# start the service
#   service start
#   service stop
#   service restart
#   service status

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

do_start() {

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

do_stop() {
    do_stop_EX $i

do_restart() {

check_status() {
    echo "do nothing"

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

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 start


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 […]