Application scenario of Samba Service in Centos system
Samba is a free software that implements SMB protocol on Linux and UNIX systems, which is composed of server and client programs. SMB (Server Messages Block, Information Service Block) is a communication protocol for sharing files and printers on the LAN. It provides sharing services for files, printers and other resources between different computers in the LAN. SMB protocol is a client / server protocol, through which clients can access shared file systems, printers, and other resources on the server. By setting "NetBIOS over TCP/IP", Samba can share resources not only with LAN hosts, but also with computers around the world.
Realize file and printer resource sharing between linux/unix and windows
First, anonymous access to Samba sharing services
1. The installation service modifies the main configuration file
Configuration file location: / etc/samba/smb.conf [root@localhost ~] # yum install samba-y # # install the Samba service [root@localhost ~] # cd / etc/samba/ # # switch to the Samba configuration file directory [root@localhost samba] # mv smb.conf smb.conf.bak # # backup [root@localhost samba] # grep-v "#" smb.conf.bak > smb.conf # # re-create a configuration file (except Uncommented) [root@localhost samba] # vim smb.conf # # modify the configuration file [global] # # Global workgroup = SAMBA security = user passdb backend = tdbsam printing = cups printcap name = cups load printers = yes Cups options = raw map to guest = Bad User # # add this item Enable anonymous user access # # press G to locate the last line Add [share] # # added share file path=/opt/test # # path public=yes # # Public access browseable=yes # # can be accessed Writable=yes # # write permission create mask=0644 # # set permission directory mask=0755
2. Create a site and start the service
[root@localhost samba] # mkdir / opt/test # # create directory [root@localhost samba] # chmod 777 / opt/test # # give full permissions [root@localhost samba] # systemctl stop firewalld.service # # turn off firewall [root@localhost samba] # setenforce 0 # # turn off enhanced function [root@localhost samba] # systemctl start smb.service # # enable Samba service
3. Verify the test results.
Note: the test machine needs to be interconnected with the Samba server
Using the WIN+R shortcut, enter the IP address of the samba server
Go back to Linux to check
[root@localhost samba] # cd / opt/test/ # # View the shared file directory and view the created text [root@localhost test] # ll-rw-r--r--. 1 nobody nobody 0 November 5 15:51 authentication of 111.txt II and Samba shared services
1. Modify the main configuration file
[root@localhost ~] # cd / etc/samba/ # # change to the Samba configuration file directory [root@localhost samba] # vim smb.conf # # modify the configuration file [global] workgroup = SAMBA security = user passdb backend = tdbsam printing = cups printcap name = cups load printers = yes Cups options = raw # map to guest = Bad User # # an anonymously accessed comment or delete # # locate the last line by G Add [test] path=/opt/test # # shared file directory path browseable=yes # # accessible, remove create mask=0644 directory mask=0755 valid users=zhangsan from public entries, lisi # # users allowed to access write list=zhangsan # # users allowed to write
2. Create smb users
[root@localhost samba] # useradd zhangsan # # create two users [root@localhost samba] # useradd lisi [root@localhost samba] # smbpasswd-a zhangsan # # create smb user and set password New SMB password: # # set password Retype new SMB password: # # confirm password Added user zhangsan. [root@localhost samba] # smbpasswd-a lisiNew SMB password:Retype new SMB password:Added user lisi. [root@localhost samba] # pdbedit-L # # list smb users zhangsan:1001:lisi:1002: [root@localhost samba] # cd / opt/ [root@localhost opt] # mkdir test # # create a shared directory [root@localhost opt] # lstest rh test2 [root@localhost opt] # chmod 777 test2/ # give the maximum permission [root@localhost opt] # systemctl restart smb # # restart the Samba service
3. Result verification
Similarly, using the WIN+R shortcut key, enter the server IP
Note: in this experiment, zhangsan is the only user with full read and write rights, and lisi can only perform read operations. Start to verify:
Third, the account name mapping of Samba shared service (account alias login)
1. Establish a mapping file
[root@localhost ~] # cd / etc/samba/ [root@localhost samba] # vim smbusers # # create an account mapping profile zhangsan = T01 T02 lisi = test1 test22, Modify the configuration file [root@localhost samba] # vim smb.conf [global] workgroup = SAMBA security = user passdb backend = tdbsam printing = cups printcap name = cups load printers = yes cups options = raw username map = / etc/samba/smbusers # # to add the alias Configuration file path [root@localhost samba] # systemctl restart smb
3. Verification result
Use aliases for login operations
Also use WIN+R shortcuts to link
4. Access control list of Samba service
To establish an access control list, you only need to modify one file.
[root@localhost samba] # vim / etc/samba/smb.conf [test] path=/opt/test browseable=yes create mask=0644 directory mask=0755 valid users=zhangsan, lisi write list=zhangsan hosts deny=192.168.13. # # add deny access to paragraph 192.168.13 [root@localhost samba] # systemctl restart smb
Result verification