系统相关
首页 > 系统相关> > Linux ❀ RHCE自研教学笔记 - Redhat 8.2 Samba服务教研笔记

Linux ❀ RHCE自研教学笔记 - Redhat 8.2 Samba服务教研笔记

作者:互联网

文章目录


Samba :是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成;SMB - Server Messages Block 信息服务块:是一种在局域网上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务;SMB协议是客户机/服务器型协议,客户机通过该协议可以访问服务器上的共享文件系统、打印机及其他资源;

1、安装服务


[root@localhost ~]# dnf install -y samba
Complete!

[root@localhost ~]# rpm -qa | grep samba
samba-common-libs-4.11.2-13.el8.x86_64
samba-common-4.11.2-13.el8.noarch
samba-client-libs-4.11.2-13.el8.x86_64

查看服务端点

[root@localhost ~]# netstat -anop | grep 445
[root@localhost ~]# ss -lntup | grep 445

2、配置文件


[root@localhost ~]# vim /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		
        security = user				

        passdb backend = tdbsam	/密码文件转为数据库;为:/var/lib/samba/private/passwd.tdb

        printing = cups				
        printcap name = cups		
        load printers = yes			/samba服务启动是否共享打印机设备;
        cups options = raw			/打印机选项;

[homes]						/用户家目录的共享配置;
        comment = Home Directories	
        valid users = %S, %D%w%S	
        browseable = No			
        read only = No				
        inherit acls = Yes			

[printers]						/打印机共享配置;
        comment = All Printers
        path = /var/tmp
        printable = Yes
        create mask = 0600
        browseable = No

[print$]						
        comment = Printer Drivers
        path = /var/lib/samba/drivers
        write list = @printadmin root
        force group = @printadmin
        create mask = 0664
        directory mask = 0775

* 参数详解

[global] /全局参数;

验证方式:

passdb backend = tdbsam	/设置用户后台;

用户后台:

分为三种smbpasswd、tdbsam、ldapsam,sam为security account manager 安全账户管理 的缩写;

[share] /共享参数;

3、服务配置


(1)共享某用户家目录 - xiaoming

服务端配置

[root@localhost ~]# vim /etc/samba/smb.conf
[global]
        workgroup = work
        security = user
[homes]
        browseable = No
        writeable = yes
[root@localhost ~]# systemctl restart smb nmb

创建共享所需的用户

[root@localhost ~]# useradd xiaoming
[root@localhost ~]# smbpasswd -a xiaoming
New SMB password:redhat
Retype new SMB password:redhat
Added user xiaoming.
[root@localhost ~]# pdbedit -a xiaoming
new password:redhat
retype new password:redhat
[root@localhost ~]# pdbedit -L
xiaoming:1003:

[root@localhost ~]# touch /home/xiaoming/test
[root@localhost ~]# ll /home/xiaoming/
total 0
-rw-r--r--. 1 root root 0 Sep 25 17:38 test

关闭防火墙与SeLinux

[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# setenforce 0

客户端配置

[root@localhost ~]# dnf install -y samba-client
Complete!

[root@localhost ~]# smbclient -L //192.168.14.131 -U xiaoming
Enter WORK\xiaoming's password: redhat

	Sharename       Type      Comment
	---------       ----      -------
	print$          Disk      Printer Drivers
	IPC$            IPC       IPC Service (Samba 4.11.2)
	xiaoming        Disk      Home Directories
SMB1 disabled -- no workgroup available

[root@localhost ~]# smbclient //192.168.14.131/xiaoming -U xiaoming
Enter WORK\xiaoming's password: redhat
Try "help" to get a list of possible commands.
smb: \> help
?              allinfo        altname        archive        backup         
blocksize      cancel         case_sensitive cd             chmod          
chown          close          del            deltree        dir            
du             echo           exit           get            getfacl        
geteas         hardlink       help           history        iosize         
lcd            link           lock           lowercase      ls             
l              mask           md             mget           mkdir          
more           mput           newer          notify         open           
posix          posix_encrypt  posix_open     posix_mkdir    posix_rmdir    
posix_unlink   posix_whoami   print          prompt         put            
pwd            q              queue          quit           readlink       
rd             recurse        reget          rename         reput          
rm             rmdir          showacls       setea          setmode        
scopy          stat           symlink        tar            tarmode        
timeout        translate      unlock         volume         vuid           
wdel           logon          listconnect    showconnect    tcon           
tdis           tid            utimes         logoff         ..   
smb: \> ls
  .                                   D        0  Fri Sep 25 17:38:55 2020
  ..                                  D        0  Fri Sep 25 17:36:51 2020
  .mozilla                           DH        0  Wed Aug 19 17:14:51 2020
  .bash_logout                        H       18  Fri Aug 30 13:30:21 2019
  .bash_profile                       H      141  Fri Aug 30 13:30:21 2019
  .bashrc                             H      312  Fri Aug 30 13:30:21 2019
  test                                N        0  Fri Sep 25 17:38:55 2020

		36678148 blocks of size 1024. 30422640 blocks available
smb: \> mget test				/只可以下载文件,不可以下载目录;
Get file test? y
getting file \test of size 0 as test (0.0 KiloBytes/sec) (average 0.0 KiloBytes/sec)
[root@localhost ~]# ll . | grep test
-rw-r--r--. 1 root root    0 Sep 25 17:43 test

挂载该用户家目录

[root@localhost ~]# mkdir /share/xiaoming -pv
mkdir: created directory '/share'
mkdir: created directory '/share/xiaoming'
[root@localhost ~]# mount //192.168.14.131/xiaoming /share/xiaoming -o username=xiaoming,password=redhat
[root@localhost ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
//192.168.14.131/xiaoming   35G  6.0G   30G  18% /share/xiaoming

[root@localhost ~]# ll /share/xiaoming/
total 0
-rwxr-xr-x. 1 root root 0 Sep 25 17:38 test

(2)共享自定义目录

需求:共享目录名称为zxc;任何人可以浏览该目录下的文件,但是不能删除别人创建的文件,只可以删除自己创建的文件;

服务端配置

[root@localhost ~]# vim /etc/samba/smb.conf
[public]
        path = /zxc
        browseable = yes
        writeable = yes
[root@localhost ~]# mkdir /zxc
[root@localhost ~]# chmod o=rwx /zxc/
[root@localhost ~]# systemctl restart smb nmb

客户端配置

[root@localhost ~]# smbclient //192.168.14.131/public -U xiaoming
Enter WORK\xiaoming's password: redhat
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Fri Sep 25 18:12:55 2020
  ..                                  D        0  Fri Sep 25 18:10:07 2020
  111.txt                             N        4  Fri Sep 25 18:12:55 2020

		36678148 blocks of size 1024. 30421624 blocks available
smb: \> mget 111.txt 
Get file 111.txt? y
getting file \111.txt of size 4 as 111.txt (3.9 KiloBytes/sec) (average 3.9 KiloBytes/sec)
smb: \> exit
[root@localhost ~]# ll | grep 111
-rw-r--r--. 1 root root    4 Sep 25 18:15 111.txt
[root@localhost ~]# pwd
/root

挂载该临时目录

[root@localhost ~]# mount //192.168.14.131/public /share/zxc/ -o username=xiaoming,password=redhat
[root@localhost ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
//192.168.14.131/xiaoming   35G  6.0G   30G  18% /share/xiaoming
//192.168.14.131/public     35G  6.0G   30G  18% /share/zxc
[root@localhost ~]# ll /share/zxc/
total 4
-rwxr-xr-x. 1 root root 4 Sep 25 18:12 111.txt

(3)共享自定义目录

需求:samba服务端是work工作组的成员,共享目录为 /test111,共享名称为test222,所有人都可以访问,只有用户aaa可以向该目录中写入文件;

服务端配置

[root@localhost ~]# vim /etc/samba/smb.conf
[test222]
        comment = test111
        path = /test111
        browseable = yes
        write list = aaa
[root@localhost ~]# mkdir /test111
[root@localhost ~]# chmod o=rwx /test111/
[root@localhost ~]# echo this is test > /test111/test111
[root@localhost ~]# systemctl restart smb nmb
[root@localhost ~]# useradd aaa
[root@localhost ~]# smbpasswd -a aaa
New SMB password:redhat
Retype new SMB password:redhat
Added user aaa.

客户端配置

[root@localhost ~]# smbclient //192.168.14.131/test222 -U aaa
Enter WORK\xiaoming's password: 
Try "help" to get a list of possible commands.
smb: \> mkdir test222
smb: \> ls
  .                                   D        0  Fri Sep 25 18:35:25 2020
  ..                                  D        0  Fri Sep 25 18:30:04 2020
  test111                             N       13  Fri Sep 25 18:30:56 2020
  test222                             D        0  Fri Sep 25 18:35:25 2020

		36678148 blocks of size 1024. 30403056 blocks available

[root@localhost ~]# smbclient //192.168.14.131/test222 -U xiaoming
Enter WORK\xiaoming's password: 
Try "help" to get a list of possible commands.
smb: \> mkdir test333
NT_STATUS_ACCESS_DENIED making remote directory \test333

(4)多用户挂载

需求:将(3)的目录挂载在客户端,并且使用用户xiaoming作为认证用户,通过用户bbb来临时获取写的权限;

[root@localhost ~]# dnf install -y cifs-utils
Complete!
[root@localhost ~]# vim /etc/fstab 
//192.168.14.131/test222        /test111  cifs    defaults,multiuser,username=xiaoming,password=redhat,sec=ntlmssp        0 0	
[root@localhost ~]# mkdir /share/test111
[root@localhost ~]# mount -a
[root@localhost ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
//192.168.14.131/xiaoming   35G  6.0G   29G  18% /share/xiaoming
//192.168.14.131/public     35G  6.0G   29G  18% /share/zxc
//192.168.14.131/test222    35G  6.0G   29G  18% /test111
[root@localhost test111]# touch test333
touch: cannot touch 'test333': Permission denied
[root@localhost test111]# useradd bbb
[root@localhost test111]# su bbb
[bbb@localhost test111]$ touch test333
touch: cannot touch 'test333': Permission denied
[bbb@localhost test111]$ cifscreds add 192.168.14.131
Password: redhat

标签:xiaoming,8.2,Redhat,笔记,samba,共享,root,smb,localhost
来源: https://blog.csdn.net/qq_42197548/article/details/120413435