How to implement SAMBA File sharing Service
Today, I would like to share with you how to achieve SAMBA file sharing service related knowledge points, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you have something to gain after reading this article, let's take a look at it.
Configure user authentication sharing
Server-side operation:
1. Turn off the firewall, turn off selunix
[root@hejie ~] # setenforce 0 [root@hejie ~] # systemctl stop firewalld
two。 Install the package
[root@hejie ~] # yum install samba-*-y
3. Start the smb service and set it to boot
[root@hejie] # systemctl start smb [root@hejie] # systemctl enable smbCreated symlink from / etc/systemd/system/multi-user.target.wants/smb.service to / usr/lib/systemd/system/smb.service.
About configuration files for Samba
[root@hejie ~] # grep-Ev'^ # | ^ $'/ etc/samba/smb.conf [global] / / Global parameter workgroup = SAMBA / / Workgroup name is very important security = user / / Security verification methods, a total of four / / share: no need to verify identity, simple and convenient Poor security / / user: you need to verify the user's password before you can access it. / / server: you need to verify the account password through the three-party server. (centrally manage accounts) / / domain: use domain controllers for authentication passdb backend = tdbsam / / define the type of user backend There are three kinds of / / smbpasswd: set the password of the Samba service program for the system user / / tdbsam: the user who creates the database file and uses the pdbedit command to establish the Samba service program / / ldapsam: account verification based on LDAP service printing = cups / / set the type of Samba shared printer printcap name = cups / / set the configuration file for shared printer load printers = yes / / set the option to share printer device cups options = raw / printer when the Samba service starts [homes] / / shared parameter comment = Home Directories / / description information valid users =% S % D%w%S / / users who are allowed to access the share browseable = No / / specify whether the share information is visible read only = Noinherit acls = [printers] comment = All Printers any string path = / var/tmp shared directory path printable = Yes create mask = 0600 browseable = No Specify whether the share can browse [print$] comment = Printer Driverspath = / var/lib/samba/driverswrite list = root users who are allowed to write to the share create mask = 0664directory mask = 0775
4. Add user "zhengran", do not create home directory, and set password.
[root@hejie] # useradd-M zhengran [root@hejie] # smbpasswd-a zhengranNew SMB password:Retype new SMB password:Added user zhengran.
Assuming that the mapping "zhengran" user here is a share user, add the following to the / etc/samba/smbusers file:
[root@hejie ~] # echo 'zhengran = share' > / etc/samba/smbusers
5. Add the following to the global configuration:
[root@hejie ~] # vim / etc/samba/smb.conf [global] workgroup = SAMBA security = user username map = / etc/samba/smbusers / / add this line passdb backend = tdbsam
6. Create a shared directory "zhengran" and change its primary group to user "zhengran"
[root@hejie] # mkdir / opt/zhengran [root@hejie] # chown-R zhengran.zhengran / opt/zhengran/ [root@hejie] # ll / opt/total 0drwxr-xr-x. 2 zhengran zhengran 6 Aug 7 17:22 zhengran
7. Configure Sharin
[root@hejie ~] # cat > > / etc/samba/smb.conf comment = zhengranwoaini / / comment > path = / opt/zhengran / / shared directory path > browseable = yes / / specify whether the share can be browsed > guest ok = yes / / specify whether the share allows guset account access > writable = yes / / specify whether the directory is writable > write list = share / / users who are allowed to write to the share The group should be represented by @, for example: write list = root,@root > public = yes / / whether anonymous access is allowed > EOF
8. Check the configuration file for syntax errors with testparm to display the configuration that will eventually take effect
[root@hejie ~] # testparmLoad smb config files from / etc/samba/smb.confrlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384) Processing section "[homes]"Processing section" [printers] "Processing section" [print$] "Processing section" [zhengran] "Loaded services file OK.Server role: ROLE_STANDALONEPress enter to see a dump of your service definitions# Global parameters [global] workgroup = SAMBAprintcap name = cupssecurity = USERusername map = / etc/samba/smbusersidmap config *: backend = tdbcups options = raw [homes] Comment = Home Directoriesbrowseable = Noinherit acls = Yesread only = Novalid users =% S% D% w% Sprinters] comment = All Printerspath = / var/tmpbrowseable = Noprintable = Yescreate mask = 0600 [print$] comment = Printer Driverspath = / var/lib/samba/driverscreate mask = 0664directory mask = 0775write list = Root [Zhengran] comment = zhengranwoainipath = / opt/zhengranguest ok = Yesread only = Nowrite list = share
9. Restart the smb service
[root@hejie ~] # systemctl restart smb
Operations on the client:
1. Installation kit
[root@hyj ~] # yum install samba-client cifs-utils-y
Check the shared resources on the samba server in the client
[root@hyj] # smbclient-L 192.168.56.11-U share Enter SAMBA\ share's password: Sharename Type Comment-print$ Disk Printer Drivers zhengran Disk zhengranwoaini IPC$ IPC IPC Service (Samba 4.6.2) Reconnecting with SMB1 for workgroup listing. Server Comment-Workgroup Master--
3. Create a directory and mount the shared resource zhengran of the samba server to the client local
[root@hyj ~] # mkdir / opt/ran [root@hyj ~] # mount-t cifs / / 192.168.56.11/zhengran / opt/ran-o username=share Password=123 [root@hyj ~] # df-hFilesystem Size Used Avail Use% Mounted on/dev/mapper/CentOS-root 17G 1016M 16G 6% / devtmpfs 982M 0 982M 0 / devtmpfs 993M 0 993M 0 / dev/shmtmpfs 993M 8.5m 984M 1% / runtmpfs 993M 0993M 0% / sys/fs/cgroup/dev/sda1 1014M 125M 890M 13% / boottmpfs 199M 0% / run/user/0//192.168.56.11/zhengran 47G 5.4G 42G 12% / opt/ran
4. Create a new file at the client mount point
[root@hyj ~] # cd / opt/ran/ [root@hyj ran] # touch 1 2 3 [root@hyj ran] # ls1 2 3
5. Verify on the server
[root@hejie ~] # cd / opt/zhengran/ [root@hejie zhengran] # ls1 2 3 configure anonymous sharing
Server side
1. Modify the configuration file
[root@hejie ~] # vim / etc/samba/smb.conf [global] workgroup = SAMBA security = user map to guest = Bad User / / add this line
two。 Create a shared directory
[root@hejie] # mkdir / opt/ranran [root@hejie ~] # chmod 777 / opt/ranran/ [root@hejie ~] # ll / opt/ranran/-ddrwxrwxrwx. 2 root root 6 Aug 7 19:24 / opt/ranran/
3. Configure Sharin
[root@hejie ~] # cat > > / etc/samba/smb.conf comment = ranranwoaini > path = / opt/ranran > browseable = yes > writable = yes > guest ok = yes > public = yes > EOF
4. Restart the service
[root@hejie ~] # systemctl restart smb
5. Check what shared resources are available on the server on the client
[root@hyj] # smbclient-L 192.168.56.11-U'Bad User'Enter SAMBA\ Bad User's password: / / hit enter directly here No need to enter password Sharename Type Comment--print$ Disk Printer Driverszhengran Disk zhengranwoainiran Disk ranranwoainiIPC$ IPC IPC Service (Samba 4.6.2) Reconnecting with SMB1 for workgroup listing.Server Comment--Workgroup Master--
6. Hang the shared resource ran of the samba server to the client
[root@hyj ~] # mount-t cifs / / 192.168.56.11/ran / opt/ran-o username='Bad User'Password for Bad User@//192.168.56.11/ran: [root@hyj ~] # df-hFilesystem Size Used Avail Use% Mounted on/dev/mapper/centos-root 17G 1016M 16G 6% / devtmpfs 982M 0 982M 0% / devtmpfs 993M 0 993M 0% / dev/shmtmpfs 993M 8.5m 984M 1% / runtmpfs 993M 0993M 0% / sys / fs/cgroup/dev/sda1 1014M 125m 890M 13% / boottmpfs 199M 0 199M 0% / run/user/0//192.168.56.11/ran 47G 5.4G 42G 12% / opt/ran
7. Go to the shared directory on the client to create a new file
[root@hyj ~] # cd / opt/ran/ [root@hyj ran] # ls [root@hyj ran] # touch a b c [root@hyj ran] # lsa b c
8. Verify on the server side
[root@hejie ~] # cd / opt/ranran/ [root@hejie ranran] # lsa b c is all the content of this article "how to implement SAMBA File sharing Service". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.