Linux: samba service (smbd)

The smb server is centos7

The yum installation used (if you don’t know how to build a local yum warehouse, you can check it) 

Linux: rpm query installation && yum installation_Bao Haichao-GNUBHCkalitarro's Blog-CSDN Blog


Introduction to samba

samba uses

1. SMB protocol
Server Message Block, service message block
2. CIFS protocol
Common Internet File System, common Internet file system

Samba has two main programs which are

 smbd and nmbd. These two daemons run continuously from server start to stop, and have different functions. All configuration information used by smbd and nmbd is stored in the smb.conf file. Smb.conf tells the smbd and nmbd daemons what to output for sharing, who to share the output with, and how to output it.

Samba provides four services based on CIFS

File and printing services, authorization and authorized ——— smbd provides 

Name resolution and browsing services ——— nmbd provides

The role of the smbd process is to process incoming SMB packages and negotiate with Linux for resources using the package

The nmbd process enables a host (or workstation) to browse a Linux server.


We use the smbd process for file transfers in this chapter 


install samba 

yum -y install samba

# Install samba service

 

 Installed

systemctl start smb start smb
systemctl start nmb start nmb
systemctl enable smb start
smb systemctl enable nmb start nmb

Replace start with stop to close

Replace enable with disable to turn off automatically

 Successfully started the service

netstat -anput | grep "smbd"

# You can view the occupied ports


Create shared users and share files

It is also very simple to prepare a file to be distributed first. If you have a ready-made file, you don’t need to create it.

mkdir -p /kali/tarro

The objects under /kali/tarro/ will be shared later

Now create shared users according to your needs, I created 2

Two users tarro1 and tarro2 respectively

Idea: first create a system user and then turn it into a shared user

useradd tarro1        

useradd tarro2

# Create two users

passwd tarro1 

passwd tarro2

#Change the passwords of two users

pdbedit -a -u tarro1

pdbedit -a -u tarro2

# Add them to the shared user. During the period, the password will be set again. This can be different from the system password. This is the user password that will access the file later

pdbedit -L

# List all shared users

 pdbedit -x -u tarro1

# Cancel the shared user tarro1

# Deleting shared users does not delete system users

 Then add tarro1 back

pdbedit -a -u tarro1        


Configure samba (core) /etc/samba/smb.conf

The location of the smb main configuration file for samba is /etc/samba/smb.conf

 test parm

# You can directly view the content of the file

vi  /etc/samba/smb.conf

# configuration file

 [global]: global settings
[homes]: user directory sharing settings
[printers]: printer sharing settings
[myshare]: custom name shared directory settings

The meaning of common global configuration items
workgroup: name of the working group
server string: server description information
security: security level, available values ​​are as follows
user, server, domain
log file: log file location, "%m" variable indicates client address
passwd backend: Set the type of shared account file
 

All of the above can be changed without

We make both tarro1 and tarro2 readable but only tarro2 can write

Append directly below

 then append

 comment = Introduction You can write whatever you like here

 This is the shared folder path

Do not allow anonymous login

 keep adding

 keep adding

 This is the user that is allowed to read

users who can write

Then save and exit wq

Then visit //samba host ip

The samba server selinux and the firewall must be closed 

systemctl restart smb

Restart the service 

We changed the permissions of the /kali/tarro file to 777 for users to write. If there is no samba write permission, it will also be blocked. 

 normal access

 login tarro2

Access successful 

write success

Go back to the server to have a look 

can also see 

But his default write permission file is 744 directory is 755

If you don’t want him to default to this, you can modify it


Modify the default permissions for writing files

vi /etc/samba/smb.conf

 

Go here again and continue to add

 

This is the default permission of the written file with read and write 

 

This is the default permission of the directory

execute for read and write

Then save and exit

 systemctl restart smb

Create two more

 

 Different from the first permission, this time it becomes the permission I specified


Linux access samba shared files

Client Linux needs to install samba-client software

yum -y install samba-client

The installation is complete

smbclient -L smb server ip -U user

smbclient -L 192.168.1.1 -U tarro2

# View shared file content

Enter the password to view

smbclient -U user//smb server ip/directory

smbclient -U tarro2 //192.168.1.1/TARRO

 Enter the password to enter

smb:\>

successfully entered

exit can exit

 We want to download the files inside to the local use get

get + filename

get 123.txt

exit exit

 Download to home directory by default

 If you want to upload a file, use put

put + local filename

put 123123.txt

exit can exit

 It is very troublesome to log in like this usually, and the smart siege lion will have a solution to directly mount the shared folder locally

mount -o username=username,password=login user password //IP/directory/local mount point
mount -o username=tarro2,password=123 //192.168.1.1/TARRO /opt

# Mount the shared folder to the local opt

Our tarro has write permission, and it is the same as a normal file after entering

 If tarro1 is only read-only, an error will be reported when writing something to the file

 

Guess you like

Origin blog.csdn.net/w14768855/article/details/131114523