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

How to run JavaScript in Jupyter Notebook

Later, I also added how to use Jupyter Notebook i...

Solve the margin: top collapse problem in CCS

The HTML structure is as follows: The CCS structu...

An article to master MySQL index query optimization skills

Preface This article summarizes some common MySQL...

jQuery realizes the picture following effect

This article shares the specific code of jQuery t...

How to make your browser talk with JavaScript

Table of contents 1. The simplest example 2. Cust...

Detailed explanation of several methods of installing software in Linux

1. RPM package installation steps: 1. Find the co...

How to automatically back up the mysql database regularly

We all know that data is priceless. If we don’t b...

13 JavaScript one-liners that will make you look like an expert

Table of contents 1. Get a random Boolean value (...

The big role of HTML meta

There are two meta attributes: name and http-equiv...

Explain how to analyze SQL efficiency

The Explain command is the first recommended comm...

JavaScript typing game

This article shares the specific code of JavaScri...

Linux file management command example analysis [display, view, statistics, etc.]

This article describes the Linux file management ...

How to backup and restore the mysql database if it is too large

Command: mysqlhotcopy This command will lock the ...