CentOS 7 Complete steps for using samba shared folders

  • 2021-07-01 08:37:00
  • OfStack

Preface

Samba is a free software for implementing SMB protocol on Linux system, which is composed of server and client program. SMB (Server Messages Block, Information Service Block) is a communication protocol for sharing files and printers in LAN, which provides sharing services for files and printers among different computers in LAN. The SMB protocol is a client/server type protocol through which clients can access shared file systems printers and other resources on the server.

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

Installing samba


yum install -y samba

Create an 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 Set to the workgroup of the  Windows  Working group of 
 security = user  # Security options, which can be  share|user|server|domain Incremental security level 
 passdb backend = tdbsam
 printing = cups
 printcap name = cups
 load printers = yes
 cups options = raw

[homes] # Sharing shares the user's home directory by default  ,  It's not safe  ,  You can annotate it 
 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 Folders 
 comment = SambaRoot
 path = /home/samba/ # Shared path 
 read only = No

Note that when you modify yourself, remove the comment after #

Add an Samba user

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


smbpasswd -a samba

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


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

Start the Samba service

Start, stop and view related commands


systemctl start smb
systemctl stop smb
systemctl status smb

Windows Access Shared Directory

Direct Win + R, enter\ 192.168. 1.20 in the running interface, that is, your Linux host address, and the user name and password input interface will pop up, and you can access it by entering the user name and password just set.

Frequently Asked Questions

If you access the shared directory under Linux under Windows, you will be prompted with no permission

Ensure that the firewall is closed or the shared directory permission is open under Linux Ensure that there is no problem with the Samba server configuration file smb. conf settings Ensure that setlinux is turned off and can be executed with setenforce 0 command; The default SELinux prohibits writes to shared directories 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


Related articles: