Bo's Oracle Station

查看: 1358|回复: 0

课程第10次

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2019-7-25 20:05:48 | 显示全部楼层 |阅读模式
2019-07-25

关于DAC/MAC和DAC中的ACL一个很好的描述:


https://www.jianshu.com/p/1129bdaaed6e

在DAC模型下,普通用户能够修改owner?(不行), 普通用户能够修改group?(只能在他所属于的那些组之间进行修改,不管主组或附组)。


  1. [root@desktop3 /]# find / -perm -4000  -o -perm -2000  2>/dev/null
  2. /run/log/journal
  3. /run/log/journal/8b1775a78c084eb8bdd8106aea565d4e
  4. /usr/bin/fusermount
  5. /usr/bin/wall
  6. /usr/bin/su
  7. /usr/bin/chage
  8. /usr/bin/gpasswd
  9. /usr/bin/newgrp
  10. /usr/bin/passwd
  11. /usr/bin/chfn
  12. /usr/bin/chsh
  13. /usr/bin/mount
  14. /usr/bin/umount
  15. /usr/bin/crontab
  16. /usr/bin/write
  17. /usr/bin/Xorg
  18. /usr/bin/pkexec
  19. /usr/bin/ssh-agent
  20. /usr/bin/at
  21. /usr/bin/sudo
  22. /usr/bin/locate
  23. /usr/bin/staprun
  24. /usr/sbin/unix_chkpwd
  25. /usr/sbin/pam_timestamp_check
  26. /usr/sbin/userhelper
  27. /usr/sbin/netreport
  28. /usr/sbin/usernetctl
  29. /usr/sbin/lockdev
  30. /usr/sbin/mount.nfs
  31. /usr/sbin/postdrop
  32. /usr/sbin/postqueue
  33. /usr/lib/polkit-1/polkit-agent-helper-1
  34. /usr/lib64/vte-2.91/gnome-pty-helper
  35. /usr/libexec/openssh/ssh-keysign
  36. /usr/libexec/sssd/krb5_child
  37. /usr/libexec/sssd/ldap_child
  38. /usr/libexec/sssd/selinux_child
  39. /usr/libexec/sssd/proxy_child
  40. /usr/libexec/qemu-bridge-helper
  41. /usr/libexec/utempter/utempter
  42. /usr/libexec/dbus-1/dbus-daemon-launch-helper
  43. /usr/libexec/flatpak-bwrap
  44. /usr/libexec/spice-gtk-x86_64/spice-client-glib-usb-acl-helper
  45. /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
  46. [root@desktop3 /]#
复制代码
目录上的组上的S位:

实验的准备:建用户user1/user2 建组sharegroup:
  1. [root@server3 ~]# useradd user1
  2. [root@server3 ~]# useradd user2
  3. [root@server3 ~]# passwd user1
  4. Changing password for user user1.
  5. New password:
  6. BAD PASSWORD: The password contains the user name in some form
  7. Retype new password:
  8. passwd: all authentication tokens updated successfully.
  9. [root@server3 ~]# passwd user2
  10. Changing password for user user2.
  11. New password:
  12. BAD PASSWORD: The password contains the user name in some form
  13. Retype new password:
  14. passwd: all authentication tokens updated successfully.
  15. [root@server3 ~]# groupadd  sharegroup
  16. [root@server3 ~]# id user1
  17. uid=1000(user1) gid=1000(user1) groups=1000(user1)
  18. [root@server3 ~]# id user2
  19. uid=1001(user2) gid=1001(user2) groups=1001(user2)
  20. [root@server3 ~]# su - user1
  21. [user1@server3 ~]$ umask
  22. 0002
  23. [user1@server3 ~]$ exit
  24. logout
  25. [root@server3 ~]# su - user2
  26. [user2@server3 ~]$ umask
  27. 0002
  28. [user2@server3 ~]$ exit
  29. logout
  30. [root@server3 ~]# gpasswd -a user1 sharegroup
  31. Adding user user1 to group sharegroup
  32. [root@server3 ~]# gpasswd -a user2 sharegroup
  33. Adding user user2 to group sharegroup
  34. [root@server3 ~]# id user1
  35. uid=1000(user1) gid=1000(user1) groups=1000(user1),1002(sharegroup)
  36. [root@server3 ~]# id user2
  37. uid=1001(user2) gid=1001(user2) groups=1001(user2),1002(sharegroup)
  38. [root@server3 ~]# su - user1
  39. Last login: Thu Jul 25 20:52:55 CST 2019 on pts/0
  40. [user1@server3 ~]$ umask
  41. 0002
  42. [user1@server3 ~]$ exit
  43. logout
  44. [root@server3 ~]# su - user2
  45. Last login: Thu Jul 25 20:53:12 CST 2019 on pts/0
  46. [user2@server3 ~]$ umask
  47. 0002
  48. [user2@server3 ~]$
复制代码

目录方面的准备工作:
  1. [root@server3 ~]# mkdir  /sharedir
  2. [root@server3 ~]# ls -ld /sharedir/
  3. drwxr-xr-x. 2 root root 6 Jul 25 21:11 /sharedir/
  4. [root@server3 ~]# umask
  5. 0022
  6. [root@server3 ~]# chown  :sharegroup /sharedir
  7. [root@server3 ~]# chgrp sharegroup  /sharedir
复制代码
准备samba这个平台:
  1. [root@server3 ~]# yum list "*samba*"
  2. Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
  3.               : manager
  4. This system is not registered with an entitlement server. You can use subscripti                                                                             on-manager to register.
  5. Installed Packages
  6. samba-client-libs.x86_64                  4.8.3-4.el7              @anaconda/7.6
  7. samba-common.noarch                       4.8.3-4.el7              @anaconda/7.6
  8. samba-common-libs.x86_64                  4.8.3-4.el7              @anaconda/7.6
  9. Available Packages
  10. samba.x86_64                              4.8.3-4.el7              base
  11. samba-client.x86_64                       4.8.3-4.el7              base
  12. samba-client-libs.i686                    4.8.3-4.el7              base
  13. samba-common-tools.x86_64                 4.8.3-4.el7              base
  14. samba-krb5-printing.x86_64                4.8.3-4.el7              base
  15. samba-libs.i686                           4.8.3-4.el7              base
  16. samba-libs.x86_64                         4.8.3-4.el7              base
  17. samba-python.x86_64                       4.8.3-4.el7              base
  18. samba-winbind.x86_64                      4.8.3-4.el7              base
  19. samba-winbind-clients.x86_64              4.8.3-4.el7              base
  20. samba-winbind-modules.i686                4.8.3-4.el7              base
  21. samba-winbind-modules.x86_64              4.8.3-4.el7              base
  22. [root@server3 ~]# yum -y install samba.x86_64
  23. Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
  24.               : manager
  25. This system is not registered with an entitlement server. You can use subscripti                                                                             on-manager to register.
  26. base                                                     | 4.3 kB     00:00
  27. Resolving Dependencies
  28. --> Running transaction check
  29. ---> Package samba.x86_64 0:4.8.3-4.el7 will be installed
  30. --> Processing Dependency: samba-common-tools = 4.8.3-4.el7 for package: samba-4                                                                             .8.3-4.el7.x86_64
  31. --> Processing Dependency: samba-libs = 4.8.3-4.el7 for package: samba-4.8.3-4.e                                                                             l7.x86_64
  32. --> Processing Dependency: libxattr-tdb-samba4.so(SAMBA_4.8.3)(64bit) for packag                                                                             e: samba-4.8.3-4.el7.x86_64
  33. --> Processing Dependency: libxattr-tdb-samba4.so()(64bit) for package: samba-4.                                                                             8.3-4.el7.x86_64
  34. --> Running transaction check
  35. ---> Package samba-common-tools.x86_64 0:4.8.3-4.el7 will be installed
  36. ---> Package samba-libs.x86_64 0:4.8.3-4.el7 will be installed
  37. --> Processing Dependency: libpytalloc-util.so.2(PYTALLOC_UTIL_2.0.6)(64bit) for                                                                              package: samba-libs-4.8.3-4.el7.x86_64
  38. --> Processing Dependency: libpytalloc-util.so.2(PYTALLOC_UTIL_2.1.6)(64bit) for                                                                              package: samba-libs-4.8.3-4.el7.x86_64
  39. --> Processing Dependency: libpytalloc-util.so.2(PYTALLOC_UTIL_2.1.9)(64bit) for                                                                              package: samba-libs-4.8.3-4.el7.x86_64
  40. --> Processing Dependency: libpytalloc-util.so.2()(64bit) for package: samba-lib                                                                             s-4.8.3-4.el7.x86_64
  41. --> Running transaction check
  42. ---> Package pytalloc.x86_64 0:2.1.13-1.el7 will be installed
  43. --> Finished Dependency Resolution

  44. Dependencies Resolved

  45. ================================================================================
  46. Package                   Arch          Version              Repository   Size
  47. ================================================================================
  48. Installing:
  49. samba                     x86_64        4.8.3-4.el7          base        680 k
  50. Installing for dependencies:
  51. pytalloc                  x86_64        2.1.13-1.el7         base         17 k
  52. samba-common-tools        x86_64        4.8.3-4.el7          base        448 k
  53. samba-libs                x86_64        4.8.3-4.el7          base        276 k

  54. Transaction Summary
  55. ================================================================================
  56. Install  1 Package (+3 Dependent packages)

  57. Total download size: 1.4 M
  58. Installed size: 3.7 M
  59. Downloading packages:
  60. (1/4): pytalloc-2.1.13-1.el7.x86_64.rpm                    |  17 kB   00:00
  61. (2/4): samba-common-tools-4.8.3-4.el7.x86_64.rpm           | 448 kB   00:00
  62. (3/4): samba-4.8.3-4.el7.x86_64.rpm                        | 680 kB   00:00
  63. (4/4): samba-libs-4.8.3-4.el7.x86_64.rpm                   | 276 kB   00:00
  64. --------------------------------------------------------------------------------
  65. Total                                              4.8 MB/s | 1.4 MB  00:00
  66. Running transaction check
  67. Running transaction test
  68. Transaction test succeeded
  69. Running transaction
  70.   Installing : pytalloc-2.1.13-1.el7.x86_64                                 1/4
  71.   Installing : samba-libs-4.8.3-4.el7.x86_64                                2/4
  72.   Installing : samba-common-tools-4.8.3-4.el7.x86_64                        3/4
  73.   Installing : samba-4.8.3-4.el7.x86_64                                     4/4
  74.   Verifying  : pytalloc-2.1.13-1.el7.x86_64                                 1/4
  75.   Verifying  : samba-4.8.3-4.el7.x86_64                                     2/4
  76.   Verifying  : samba-common-tools-4.8.3-4.el7.x86_64                        3/4
  77.   Verifying  : samba-libs-4.8.3-4.el7.x86_64                                4/4

  78. Installed:
  79.   samba.x86_64 0:4.8.3-4.el7

  80. Dependency Installed:
  81.   pytalloc.x86_64 0:2.1.13-1.el7     samba-common-tools.x86_64 0:4.8.3-4.el7
  82.   samba-libs.x86_64 0:4.8.3-4.el7

  83. Complete!
  84. [root@server3 ~]#
复制代码

配置samba:
  1. [root@server3 ~]# cd /etc
  2. [root@server3 etc]# cd samba/
  3. [root@server3 samba]# pwd
  4. /etc/samba
  5. [root@server3 samba]# vim smb.conf
复制代码
  1. [root@server3 samba]# vim smb.conf
  2. # read the smb.conf manpage.
  3. # Run 'testparm' to verify the config is correct after
  4. # you modified it.

  5. [global]
  6.         workgroup = SAMBA
  7.         security = user

  8.         passdb backend = tdbsam

  9.         printing = cups
  10.         printcap name = cups
  11.         load printers = yes
  12.         cups options = raw

  13. [homes]
  14.         comment = Home Directories
  15.         valid users = %S, %D%w%S
  16.         browseable = No
  17.         read only = No
  18.         inherit acls = Yes

  19. [printers]
  20.         comment = All Printers
  21.         path = /var/tmp
  22.         printable = Yes
  23.         create mask = 0600
  24.         browseable = No

  25. [print$]
  26.         comment = Printer Drivers
  27.         path = /var/lib/samba/drivers
  28.         write list = @printadmin root
  29.         force group = @printadmin
  30.         create mask = 0664
  31.         directory mask = 0775


  32. [sharedir]
  33.         comment = Share Dir
  34.         path = /sharedir
  35.         write list = @sharegroup

复制代码
  1. [root@server3 samba]# systemctl enable smb
  2. Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
  3. [root@server3 samba]# systemctl start smb
  4. [root@server3 samba]# systemctl status smb
  5. ● smb.service - Samba SMB Daemon
  6.    Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
  7.    Active: active (running) since Thu 2019-07-25 21:25:09 CST; 6s ago
  8.      Docs: man:smbd(8)
  9.            man:samba(7)
  10.            man:smb.conf(5)
  11. Main PID: 10661 (smbd)
  12.    Status: "smbd: ready to serve connections..."
  13.     Tasks: 4
  14.    CGroup: /system.slice/smb.service
  15.            ├─10661 /usr/sbin/smbd --foreground --no-process-group
  16.            ├─10664 /usr/sbin/smbd --foreground --no-process-group
  17.            ├─10665 /usr/sbin/smbd --foreground --no-process-group
  18.            └─10666 /usr/sbin/smbd --foreground --no-process-group

  19. Jul 25 21:25:09 server3.example.com systemd[1]: Starting Samba SMB Daemon...
  20. Jul 25 21:25:09 server3.example.com smbd[10661]: [2019/07/25 21:25:09.895521,  0] ../lib/util/become_daemon.c:138(daemon_ready)
  21. Jul 25 21:25:09 server3.example.com smbd[10661]:   daemon_ready: STATUS=daemon 'smbd' finished starting up and ready to serve connections
  22. Jul 25 21:25:09 server3.example.com systemd[1]: Started Samba SMB Daemon.
  23. [root@server3 samba]#
复制代码
打开防火墙和建立samba用户:

  1. [root@server3 samba]# smbpasswd  -a user1
  2. New SMB password:
  3. Retype new SMB password:
  4. Added user user1.
  5. [root@server3 samba]# smbpasswd  -a user2
  6. New SMB password:
  7. Retype new SMB password:
  8. Added user user2.
复制代码

拿linux做客户端:
  1. [root@desktop3 ~]# yum -y install samba-client.x86_64
  2. Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
  3.               : manager
  4. This system is not registered with an entitlement server. You can use subscription-manager to register.
  5. base                                                     | 4.3 kB     00:00
  6. Resolving Dependencies
  7. --> Running transaction check
  8. ---> Package samba-client.x86_64 0:4.8.3-4.el7 will be installed
  9. --> Finished Dependency Resolution

  10. Dependencies Resolved

  11. ================================================================================
  12. Package               Arch            Version              Repository     Size
  13. ================================================================================
  14. Installing:
  15. samba-client          x86_64          4.8.3-4.el7          base          618 k

  16. Transaction Summary
  17. ================================================================================
  18. Install  1 Package

  19. Total download size: 618 k
  20. Installed size: 2.0 M
  21. Downloading packages:
  22. samba-client-4.8.3-4.el7.x86_64.rpm                        | 618 kB   00:00
  23. Running transaction check
  24. Running transaction test
  25. Transaction test succeeded
  26. Running transaction
  27.   Installing : samba-client-4.8.3-4.el7.x86_64                              1/1
  28.   Verifying  : samba-client-4.8.3-4.el7.x86_64                              1/1

  29. Installed:
  30.   samba-client.x86_64 0:4.8.3-4.el7

  31. Complete!
  32. [root@desktop3 ~]# smbclient -L //192.168.0.103
  33. Enter SAMBA\root's password:
  34. [root@desktop3 ~]# smbclient -L //192.168.0.103 -U user1%oracleredhat

  35.         Sharename       Type      Comment
  36.         ---------       ----      -------
  37.         print[        DISCUZ_CODE_35        ]nbsp;         Disk      Printer Drivers
  38.         sharedir        Disk      Share Dir
  39.         IPC[        DISCUZ_CODE_35        ]nbsp;           IPC       IPC Service (Samba 4.8.3)
  40.         user1           Disk      Home Directories
  41. Reconnecting with SMB1 for workgroup listing.

  42.         Server               Comment
  43.         ---------            -------

  44.         Workgroup            Master
  45.         ---------            -------
  46. [root@desktop3 ~]#
复制代码
如果在server3.example.com上不想默认共享出家目录的话,请:
  1. [root@server3 samba]# vim smb.conf
  2. # See smb.conf.example for a more detailed config file or
  3. # read the smb.conf manpage.
  4. # Run 'testparm' to verify the config is correct after
  5. # you modified it.

  6. [global]
  7.         workgroup = SAMBA
  8.         security = user

  9.         passdb backend = tdbsam

  10.         printing = cups
  11.         printcap name = cups
  12.         load printers = yes
  13.         cups options = raw

  14. #[homes]
  15. #       comment = Home Directories
  16. #       valid users = %S, %D%w%S
  17. #       browseable = No
  18. #       read only = No
  19. #       inherit acls = Yes

  20. [printers]
  21.         comment = All Printers
  22.         path = /var/tmp
  23.         printable = Yes
  24.         create mask = 0600
  25.         browseable = No

  26. [print$]
  27.         comment = Printer Drivers
  28.         path = /var/lib/samba/drivers
  29.         write list = @printadmin root
  30.         force group = @printadmin
  31.         create mask = 0664
  32.         directory mask = 0775


  33. [sharedir]
  34.         comment = Share Dir
  35.         path = /sharedir
  36.         write list = @sharegroup
复制代码
在客户端这边看:
  1. [root@desktop3 ~]# smbclient -L //192.168.0.103 -U user1%oracleredhat

  2.         Sharename       Type      Comment
  3.         ---------       ----      -------
  4.         print[        DISCUZ_CODE_21        ]nbsp;         Disk      Printer Drivers
  5.         sharedir        Disk      Share Dir
  6.         IPC[        DISCUZ_CODE_21        ]nbsp;           IPC       IPC Service (Samba 4.8.3)
  7. Reconnecting with SMB1 for workgroup listing.

  8.         Server               Comment
  9.         ---------            -------

  10.         Workgroup            Master
  11.         ---------            -------
复制代码

这么用:
  1. [root@desktop3 ~]# mount  -t cifs -o username=user1,password=oracleredhat  //192.168.0.103/sharedir  /mnt
复制代码

还有问题:
DAC本地允许,而MAC远程不允许的问题:
允许:
  1. [user1@server3 ~]$ cd /sharedir/
  2. [user1@server3 sharedir]$ ls
  3. [user1@server3 sharedir]$ ls -ld
  4. drwxr-xr-x. 2 root sharegroup 6 Jul 25 21:11 .
  5. [user1@server3 sharedir]$
复制代码
不允许:
  1. [root@desktop3 ~]# mount  -t cifs -o username=user1,password=oracleredhat  //192.168.0.103/sharedir  /mnt
  2. [root@desktop3 ~]# cd /mnt
  3. [root@desktop3 mnt]# ls
  4. ls: reading directory .: Permission denied
  5. [root@desktop3 mnt]# ls
  6. ls: reading directory .: Permission denied
  7. [root@desktop3 mnt]#
复制代码

QQ图片20190725215051.png

  1. [root@server3 ~]# chcon -t samba_share_t /sharedir/
复制代码

samba有自己的默认掩码,会覆盖用户的umask:
  1. [root@server3 sharedir]# ls -l
  2. total 8
  3. -rwxr--r--. 1 user1 user1 20 Jul 25 21:55 user1.txt
  4. -rwxr--r--. 1 user2 user2 18 Jul 25 21:54 user2.txt
  5. [root@server3 sharedir]# su - user1
  6. Last login: Thu Jul 25 21:45:28 CST 2019 on pts/0
  7. [user1@server3 ~]$ umask
  8. 0002
  9. [user1@server3 ~]$ 744
复制代码

如果要确保掩码一致的话,要:


  1. [root@server3 samba]# vim smb.conf
  2.         load printers = yes
  3.         cups options = raw

  4. #[homes]
  5. #       comment = Home Directories
  6. #       valid users = %S, %D%w%S
  7. #       browseable = No
  8. #       read only = No
  9. #       inherit acls = Yes

  10. [printers]
  11.         comment = All Printers
  12.         path = /var/tmp
  13.         printable = Yes
  14.         create mask = 0600
  15.         browseable = No

  16. [print$]
  17.         comment = Printer Drivers
  18.         path = /var/lib/samba/drivers
  19.         write list = @printadmin root
  20.         force group = @printadmin
  21.         create mask = 0664
  22.         directory mask = 0775


  23. [sharedir]
  24.         comment = Share Dir
  25.         path = /sharedir
  26.         write list = @sharegroup
  27.         create mask = 0664
复制代码



















回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-5-20 15:00 , Processed in 0.038488 second(s), 27 queries .

快速回复 返回顶部 返回列表