|
2019-07-25
关于DAC/MAC和DAC中的ACL一个很好的描述:
https://www.jianshu.com/p/1129bdaaed6e
在DAC模型下,普通用户能够修改owner?(不行), 普通用户能够修改group?(只能在他所属于的那些组之间进行修改,不管主组或附组)。
- [root@desktop3 /]# find / -perm -4000 -o -perm -2000 2>/dev/null
- /run/log/journal
- /run/log/journal/8b1775a78c084eb8bdd8106aea565d4e
- /usr/bin/fusermount
- /usr/bin/wall
- /usr/bin/su
- /usr/bin/chage
- /usr/bin/gpasswd
- /usr/bin/newgrp
- /usr/bin/passwd
- /usr/bin/chfn
- /usr/bin/chsh
- /usr/bin/mount
- /usr/bin/umount
- /usr/bin/crontab
- /usr/bin/write
- /usr/bin/Xorg
- /usr/bin/pkexec
- /usr/bin/ssh-agent
- /usr/bin/at
- /usr/bin/sudo
- /usr/bin/locate
- /usr/bin/staprun
- /usr/sbin/unix_chkpwd
- /usr/sbin/pam_timestamp_check
- /usr/sbin/userhelper
- /usr/sbin/netreport
- /usr/sbin/usernetctl
- /usr/sbin/lockdev
- /usr/sbin/mount.nfs
- /usr/sbin/postdrop
- /usr/sbin/postqueue
- /usr/lib/polkit-1/polkit-agent-helper-1
- /usr/lib64/vte-2.91/gnome-pty-helper
- /usr/libexec/openssh/ssh-keysign
- /usr/libexec/sssd/krb5_child
- /usr/libexec/sssd/ldap_child
- /usr/libexec/sssd/selinux_child
- /usr/libexec/sssd/proxy_child
- /usr/libexec/qemu-bridge-helper
- /usr/libexec/utempter/utempter
- /usr/libexec/dbus-1/dbus-daemon-launch-helper
- /usr/libexec/flatpak-bwrap
- /usr/libexec/spice-gtk-x86_64/spice-client-glib-usb-acl-helper
- /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
- [root@desktop3 /]#
复制代码 目录上的组上的S位:
实验的准备:建用户user1/user2 建组sharegroup:
- [root@server3 ~]# useradd user1
- [root@server3 ~]# useradd user2
- [root@server3 ~]# passwd user1
- Changing password for user user1.
- New password:
- BAD PASSWORD: The password contains the user name in some form
- Retype new password:
- passwd: all authentication tokens updated successfully.
- [root@server3 ~]# passwd user2
- Changing password for user user2.
- New password:
- BAD PASSWORD: The password contains the user name in some form
- Retype new password:
- passwd: all authentication tokens updated successfully.
- [root@server3 ~]# groupadd sharegroup
- [root@server3 ~]# id user1
- uid=1000(user1) gid=1000(user1) groups=1000(user1)
- [root@server3 ~]# id user2
- uid=1001(user2) gid=1001(user2) groups=1001(user2)
- [root@server3 ~]# su - user1
- [user1@server3 ~]$ umask
- 0002
- [user1@server3 ~]$ exit
- logout
- [root@server3 ~]# su - user2
- [user2@server3 ~]$ umask
- 0002
- [user2@server3 ~]$ exit
- logout
- [root@server3 ~]# gpasswd -a user1 sharegroup
- Adding user user1 to group sharegroup
- [root@server3 ~]# gpasswd -a user2 sharegroup
- Adding user user2 to group sharegroup
- [root@server3 ~]# id user1
- uid=1000(user1) gid=1000(user1) groups=1000(user1),1002(sharegroup)
- [root@server3 ~]# id user2
- uid=1001(user2) gid=1001(user2) groups=1001(user2),1002(sharegroup)
- [root@server3 ~]# su - user1
- Last login: Thu Jul 25 20:52:55 CST 2019 on pts/0
- [user1@server3 ~]$ umask
- 0002
- [user1@server3 ~]$ exit
- logout
- [root@server3 ~]# su - user2
- Last login: Thu Jul 25 20:53:12 CST 2019 on pts/0
- [user2@server3 ~]$ umask
- 0002
- [user2@server3 ~]$
复制代码
目录方面的准备工作:
- [root@server3 ~]# mkdir /sharedir
- [root@server3 ~]# ls -ld /sharedir/
- drwxr-xr-x. 2 root root 6 Jul 25 21:11 /sharedir/
- [root@server3 ~]# umask
- 0022
- [root@server3 ~]# chown :sharegroup /sharedir
- [root@server3 ~]# chgrp sharegroup /sharedir
复制代码 准备samba这个平台:
- [root@server3 ~]# yum list "*samba*"
- Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
- : manager
- This system is not registered with an entitlement server. You can use subscripti on-manager to register.
- Installed Packages
- samba-client-libs.x86_64 4.8.3-4.el7 @anaconda/7.6
- samba-common.noarch 4.8.3-4.el7 @anaconda/7.6
- samba-common-libs.x86_64 4.8.3-4.el7 @anaconda/7.6
- Available Packages
- samba.x86_64 4.8.3-4.el7 base
- samba-client.x86_64 4.8.3-4.el7 base
- samba-client-libs.i686 4.8.3-4.el7 base
- samba-common-tools.x86_64 4.8.3-4.el7 base
- samba-krb5-printing.x86_64 4.8.3-4.el7 base
- samba-libs.i686 4.8.3-4.el7 base
- samba-libs.x86_64 4.8.3-4.el7 base
- samba-python.x86_64 4.8.3-4.el7 base
- samba-winbind.x86_64 4.8.3-4.el7 base
- samba-winbind-clients.x86_64 4.8.3-4.el7 base
- samba-winbind-modules.i686 4.8.3-4.el7 base
- samba-winbind-modules.x86_64 4.8.3-4.el7 base
- [root@server3 ~]# yum -y install samba.x86_64
- Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
- : manager
- This system is not registered with an entitlement server. You can use subscripti on-manager to register.
- base | 4.3 kB 00:00
- Resolving Dependencies
- --> Running transaction check
- ---> Package samba.x86_64 0:4.8.3-4.el7 will be installed
- --> Processing Dependency: samba-common-tools = 4.8.3-4.el7 for package: samba-4 .8.3-4.el7.x86_64
- --> Processing Dependency: samba-libs = 4.8.3-4.el7 for package: samba-4.8.3-4.e l7.x86_64
- --> Processing Dependency: libxattr-tdb-samba4.so(SAMBA_4.8.3)(64bit) for packag e: samba-4.8.3-4.el7.x86_64
- --> Processing Dependency: libxattr-tdb-samba4.so()(64bit) for package: samba-4. 8.3-4.el7.x86_64
- --> Running transaction check
- ---> Package samba-common-tools.x86_64 0:4.8.3-4.el7 will be installed
- ---> Package samba-libs.x86_64 0:4.8.3-4.el7 will be installed
- --> Processing Dependency: libpytalloc-util.so.2(PYTALLOC_UTIL_2.0.6)(64bit) for package: samba-libs-4.8.3-4.el7.x86_64
- --> Processing Dependency: libpytalloc-util.so.2(PYTALLOC_UTIL_2.1.6)(64bit) for package: samba-libs-4.8.3-4.el7.x86_64
- --> Processing Dependency: libpytalloc-util.so.2(PYTALLOC_UTIL_2.1.9)(64bit) for package: samba-libs-4.8.3-4.el7.x86_64
- --> Processing Dependency: libpytalloc-util.so.2()(64bit) for package: samba-lib s-4.8.3-4.el7.x86_64
- --> Running transaction check
- ---> Package pytalloc.x86_64 0:2.1.13-1.el7 will be installed
- --> Finished Dependency Resolution
- Dependencies Resolved
- ================================================================================
- Package Arch Version Repository Size
- ================================================================================
- Installing:
- samba x86_64 4.8.3-4.el7 base 680 k
- Installing for dependencies:
- pytalloc x86_64 2.1.13-1.el7 base 17 k
- samba-common-tools x86_64 4.8.3-4.el7 base 448 k
- samba-libs x86_64 4.8.3-4.el7 base 276 k
- Transaction Summary
- ================================================================================
- Install 1 Package (+3 Dependent packages)
- Total download size: 1.4 M
- Installed size: 3.7 M
- Downloading packages:
- (1/4): pytalloc-2.1.13-1.el7.x86_64.rpm | 17 kB 00:00
- (2/4): samba-common-tools-4.8.3-4.el7.x86_64.rpm | 448 kB 00:00
- (3/4): samba-4.8.3-4.el7.x86_64.rpm | 680 kB 00:00
- (4/4): samba-libs-4.8.3-4.el7.x86_64.rpm | 276 kB 00:00
- --------------------------------------------------------------------------------
- Total 4.8 MB/s | 1.4 MB 00:00
- Running transaction check
- Running transaction test
- Transaction test succeeded
- Running transaction
- Installing : pytalloc-2.1.13-1.el7.x86_64 1/4
- Installing : samba-libs-4.8.3-4.el7.x86_64 2/4
- Installing : samba-common-tools-4.8.3-4.el7.x86_64 3/4
- Installing : samba-4.8.3-4.el7.x86_64 4/4
- Verifying : pytalloc-2.1.13-1.el7.x86_64 1/4
- Verifying : samba-4.8.3-4.el7.x86_64 2/4
- Verifying : samba-common-tools-4.8.3-4.el7.x86_64 3/4
- Verifying : samba-libs-4.8.3-4.el7.x86_64 4/4
- Installed:
- samba.x86_64 0:4.8.3-4.el7
- Dependency Installed:
- pytalloc.x86_64 0:2.1.13-1.el7 samba-common-tools.x86_64 0:4.8.3-4.el7
- samba-libs.x86_64 0:4.8.3-4.el7
- Complete!
- [root@server3 ~]#
复制代码
配置samba:
- [root@server3 ~]# cd /etc
- [root@server3 etc]# cd samba/
- [root@server3 samba]# pwd
- /etc/samba
- [root@server3 samba]# vim smb.conf
复制代码- [root@server3 samba]# vim smb.conf
- # 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
- printing = cups
- printcap name = cups
- load printers = yes
- 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
- [sharedir]
- comment = Share Dir
- path = /sharedir
- write list = @sharegroup
复制代码- [root@server3 samba]# systemctl enable smb
- Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
- [root@server3 samba]# systemctl start smb
- [root@server3 samba]# systemctl status smb
- ● smb.service - Samba SMB Daemon
- Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
- Active: active (running) since Thu 2019-07-25 21:25:09 CST; 6s ago
- Docs: man:smbd(8)
- man:samba(7)
- man:smb.conf(5)
- Main PID: 10661 (smbd)
- Status: "smbd: ready to serve connections..."
- Tasks: 4
- CGroup: /system.slice/smb.service
- ├─10661 /usr/sbin/smbd --foreground --no-process-group
- ├─10664 /usr/sbin/smbd --foreground --no-process-group
- ├─10665 /usr/sbin/smbd --foreground --no-process-group
- └─10666 /usr/sbin/smbd --foreground --no-process-group
- Jul 25 21:25:09 server3.example.com systemd[1]: Starting Samba SMB Daemon...
- 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)
- Jul 25 21:25:09 server3.example.com smbd[10661]: daemon_ready: STATUS=daemon 'smbd' finished starting up and ready to serve connections
- Jul 25 21:25:09 server3.example.com systemd[1]: Started Samba SMB Daemon.
- [root@server3 samba]#
复制代码 打开防火墙和建立samba用户:
- [root@server3 samba]# smbpasswd -a user1
- New SMB password:
- Retype new SMB password:
- Added user user1.
- [root@server3 samba]# smbpasswd -a user2
- New SMB password:
- Retype new SMB password:
- Added user user2.
复制代码
拿linux做客户端:
- [root@desktop3 ~]# yum -y install samba-client.x86_64
- Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
- : manager
- This system is not registered with an entitlement server. You can use subscription-manager to register.
- base | 4.3 kB 00:00
- Resolving Dependencies
- --> Running transaction check
- ---> Package samba-client.x86_64 0:4.8.3-4.el7 will be installed
- --> Finished Dependency Resolution
- Dependencies Resolved
- ================================================================================
- Package Arch Version Repository Size
- ================================================================================
- Installing:
- samba-client x86_64 4.8.3-4.el7 base 618 k
- Transaction Summary
- ================================================================================
- Install 1 Package
- Total download size: 618 k
- Installed size: 2.0 M
- Downloading packages:
- samba-client-4.8.3-4.el7.x86_64.rpm | 618 kB 00:00
- Running transaction check
- Running transaction test
- Transaction test succeeded
- Running transaction
- Installing : samba-client-4.8.3-4.el7.x86_64 1/1
- Verifying : samba-client-4.8.3-4.el7.x86_64 1/1
- Installed:
- samba-client.x86_64 0:4.8.3-4.el7
- Complete!
- [root@desktop3 ~]# smbclient -L //192.168.0.103
- Enter SAMBA\root's password:
- [root@desktop3 ~]# smbclient -L //192.168.0.103 -U user1%oracleredhat
- Sharename Type Comment
- --------- ---- -------
- print[ DISCUZ_CODE_35 ]nbsp; Disk Printer Drivers
- sharedir Disk Share Dir
- IPC[ DISCUZ_CODE_35 ]nbsp; IPC IPC Service (Samba 4.8.3)
- user1 Disk Home Directories
- Reconnecting with SMB1 for workgroup listing.
- Server Comment
- --------- -------
- Workgroup Master
- --------- -------
- [root@desktop3 ~]#
复制代码 如果在server3.example.com上不想默认共享出家目录的话,请:
- [root@server3 samba]# vim 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
- printing = cups
- printcap name = cups
- load printers = yes
- 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
- [sharedir]
- comment = Share Dir
- path = /sharedir
- write list = @sharegroup
复制代码 在客户端这边看:
- [root@desktop3 ~]# smbclient -L //192.168.0.103 -U user1%oracleredhat
- Sharename Type Comment
- --------- ---- -------
- print[ DISCUZ_CODE_21 ]nbsp; Disk Printer Drivers
- sharedir Disk Share Dir
- IPC[ DISCUZ_CODE_21 ]nbsp; IPC IPC Service (Samba 4.8.3)
- Reconnecting with SMB1 for workgroup listing.
- Server Comment
- --------- -------
- Workgroup Master
- --------- -------
复制代码
这么用:
- [root@desktop3 ~]# mount -t cifs -o username=user1,password=oracleredhat //192.168.0.103/sharedir /mnt
复制代码
还有问题:
DAC本地允许,而MAC远程不允许的问题:
允许:
- [user1@server3 ~]$ cd /sharedir/
- [user1@server3 sharedir]$ ls
- [user1@server3 sharedir]$ ls -ld
- drwxr-xr-x. 2 root sharegroup 6 Jul 25 21:11 .
- [user1@server3 sharedir]$
复制代码 不允许:
- [root@desktop3 ~]# mount -t cifs -o username=user1,password=oracleredhat //192.168.0.103/sharedir /mnt
- [root@desktop3 ~]# cd /mnt
- [root@desktop3 mnt]# ls
- ls: reading directory .: Permission denied
- [root@desktop3 mnt]# ls
- ls: reading directory .: Permission denied
- [root@desktop3 mnt]#
复制代码
- [root@server3 ~]# chcon -t samba_share_t /sharedir/
复制代码
samba有自己的默认掩码,会覆盖用户的umask:
- [root@server3 sharedir]# ls -l
- total 8
- -rwxr--r--. 1 user1 user1 20 Jul 25 21:55 user1.txt
- -rwxr--r--. 1 user2 user2 18 Jul 25 21:54 user2.txt
- [root@server3 sharedir]# su - user1
- Last login: Thu Jul 25 21:45:28 CST 2019 on pts/0
- [user1@server3 ~]$ umask
- 0002
- [user1@server3 ~]$ 744
复制代码
如果要确保掩码一致的话,要:
- [root@server3 samba]# vim smb.conf
- load printers = yes
- 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
- [sharedir]
- comment = Share Dir
- path = /sharedir
- write list = @sharegroup
- create mask = 0664
复制代码
|
|