Creating shared folders for Linux (centos7) using Samba


Add Samba service for test server

Samba service is a service for Linux file sharing, which can be understood as “shared folder of Linux”. 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 enter\\, view all shared directories

|Server IP | Samba account | Samba password|
| | Linux account (e.g. whqt) | 123456|
| | | |
| | | |

The benefits of using Samba are that copying logs and editing configuration files can be carried out directly under windows, or even using visual studio to open the code project on the server for development under windows. Even if the server is restarted, it will not be affected.

Installing and configuring Samba services

Installing Samba

yum install samba

Configuring Samba

Add user and password for Samba

#The user added here must be an existing Linux user on this machine
 smbpasswd -a whqt

Boot Samba service

Because centos7 adopts relatively 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’s intranet and is relatively safe, these services will be disabled 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 startup and the priority of startup and shutdown. For example:# chkconfig: 2345 55 25
  • Description of the service

The service script needs to be implementedstart,stop,restart,statusParameter functions, in short, the following functions need to be realized:

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 the services managed by chkconfig

Just like starting any ordinary service

sudo service start