Complete steps to use samba to share folders in CentOS 7

Complete steps to use samba to share folders in CentOS 7

Preface

Samba is a free software that implements the SMB protocol on Linux 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 the client can access shared file systems, printers, and other resources on the server.

For example, I want to share the folder /home/samba with other computers.

Install samba

yum install -y samba

Create samba user

useradd samba

Modify samba configuration

The configuration file is /etc/samba/smb.conf

# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.

[global]
 workgroup = SAMBA #samba workgroup, set to Windows workgroup security = user #security options, can be share|user|server|domain, security level increases passdb backend = tdbsam
 printing = cups
 printcap name = cups
 load printers = yes
 cups options = raw

[homes] #By default, the user's home directory will be shared. This is unsafe. You can comment it out with comment = Home Directories
 valid users = %S, %D%w%S
 browseable = No
 read only = No
 inherit acls = Yes

[printers] #Printer sharing comment = All Printers
 path = /var/tmp
 printable = Yes
 create mask = 0600
 browseable = No

[print$]
 comment = Printer Drivers
 path = /var/lib/samba/drivers
 write list = root
 create mask = 0664
 directory mask = 0775

[rootdir] #Custom shared folder comment = SambaRoot
 path = /home/samba/ #Shared path read only = No

Note: remove the comment after # when modifying it yourself

Adding Samba Users

Add the samba user you just created and set the corresponding password according to the prompts

smbpasswd -a samba

The smbpasswd command is used to maintain the user accounts of the Samba server, as follows:

// Add Samba user account # smbpasswd -a sambauser 
// Disable the Samba user account # smbpasswd -d sambauser
// Enable Samba user account # smbpasswd -e sambauser
// Delete Samba user account # smbpasswd -x sambauser

Start Samba Service

Start, stop, and view related commands

systemctl start smb
systemctl stop smb
systemctl status smb

Windows access shared directories

Simply press Win + R, enter \192.168.1.20 in the run interface, which is your Linux host address. The username and password input interface will pop up. Enter the username and password you just set to access it.

Frequently asked questions

If you access a shared directory in Linux from Windows, you will get a message saying you do not have permission.

  1. Make sure the Linux firewall is turned off or open the shared directory permissions
  2. Make sure that the Samba server configuration file smb.conf is set correctly.
  3. Make sure setlinux is turned off, you can use the setenforce 0 command to execute; by default SELinux prohibits writing to the shared directory on the Samba server on the network

Samb also needs to open the following four ports

UDP 137, UDP 138, TCP 139, TCP 445

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Distributed deployment of pyspider in centos7
  • Construction and development of Hadoop distributed environment based on CentOS
  • Complete steps to build NFS file sharing storage service in CentOS 7
  • How to move mysql5.7.19 data storage location in Centos7
  • A brief analysis of how to access Windows 10 host folders from CentOS 8 virtual machines
  • Detailed tutorial for installing nginx on centos8 (picture and text)
  • How to add Nginx to system services in CentOS7
  • Centos7 configuration fastdfs and nginx distributed file storage system implementation process analysis

<<:  Ubuntu 18.04 MySQL 8.0 installation and configuration method graphic tutorial

>>:  How to print highlighted code in nodejs console

Recommend

Several important MySQL variables

There are many MySQL variables, some of which are...

How to implement a multi-terminal bridging platform based on websocket in JS

Table of contents 1. What to debug 2. Features of...

js canvas realizes slider verification

This article example shares the specific code of ...

Installation steps of docker-ce on Raspberry Pi 4b ubuntu19 server

The Raspberry Pi model is 4b, 1G RAM. The system ...

Basic operation tutorial of files and permissions in centos

Preface Before we begin, we should briefly unders...

A bug fix for Tomcat's automatic shutdown

Preface Recently, a Java EE web project that has ...

Introduction to ufw firewall in Linux

Let's take a look at ufw (Uncomplicated Firew...

Analysis and treatment of scroll bars in both HTML and embedded Flash

We often encounter this situation when doing devel...

The most basic code for web pages

◆Add to favorites illustrate Click to add your we...

How to create, start, and stop a Docker container

1. A container is an independently running applic...

Implementation steps of encapsulating components based on React

Table of contents Preface How does antd encapsula...

Analyze how uniapp dynamically obtains the interface domain name

background The interface domain name is not hard-...

Specific use of Linux which command

We often want to find a file in Linux, but we don...

Detailed explanation of creating and calling MySQL stored procedures

Table of contents Preface Stored Procedure: 1. Cr...