Linux 练习 - 用户组和权限管理

1、创建用户 gentoo ,附加组为 bin 和 root ,默认 shell 为 /bin/csh ,注释信息为 “Gentoo Distribution”
[root@centos7 ~]# useradd -G bin,root -s /bin/csh -c "Gentoo Distribution" gentoo
[root@centos7 ~]# id gentoo
uid=2007(gentoo) gid=2007(gentoo) groups=2007(gentoo),0(root),1(bin)
2、创建下面的用户、组和组成员关系
  • 名字为 webs 的组
[root@centos7 ~]# groupadd webs
[root@centos7 ~]# getent group webs
webs:x:2022:
  • 用户 nginx ,使用 webs 作为附加组,密码为 20200515
[root@centos7 ~]# useradd -G webs nginx
[root@centos7 ~]# echo "20200515" | passwd --stdin nginx
Changing password for user nginx.
passwd: all authentication tokens updated successfully.
  • 用户 varnish ,使用 webs 作为附加组,密码为 20200515
[root@centos7 ~]# useradd -G webs varnish
[root@centos7 ~]# echo "20200515" | passwd --stdin varnish
Changing password for user varnish.
passwd: all authentication tokens updated successfully.
  • 用户 mysql ,不可交互登录系统,且不是 webs 的成员,密码为 20200515
[root@centos7 ~]# useradd -s /sbin/nologin mysql
[root@centos7 ~]# echo "20200515" | passwd --stdin mysql
Changing password for user mysql.
passwd: all authentication tokens updated successfully.
3、当用户 docker 对 /testdir 目录无执行权限时,意味着无法做哪些操作?

无法用 cd 命令进入目录
无法列出目录中文件的元数据

4、当用户 mongodb 对 /testdir 目录无读权限时,意味着无法做哪些操作?

无法列出目录的所有文件(无法 tab 自动补全)

5、当用户 redis 对 /testdir 目录无写权限时,该目录下的只读文件 file1 是否可修改和删除?

不行

6、当用户 zabbix 对 /testdir 目录有写和执行权限时,该目录下的只读文件 file1 是否可修改和删除?

不能修改,可以删除

7、复制 /etc/fstab 文件到 /var/tmp下,设置文件所有者为 tomcat 读写权限,所属组为 apps 组有读写权限,其他人无权限
[root@centos7 ~]# cp /etc/fstab /var/tmp
[root@centos7 ~]# useradd tomcat
[root@centos7 ~]# groupadd apps
[root@centos7 ~]# chown tomcat.apps /var/tmp/fstab
[root@centos7 ~]# chmod 660 /var/tmp/fstab 
[root@centos7 ~]# ll /var/tmp/fstab
-rw-rw----. 1 tomcat apps 353 May 21 15:19 /var/tmp/fstab
8、误删除了用户 git 的家目录,请重建并恢复该用户家目录及相应的权限属性
[root@centos7 ~]# cp -r /etc/skel/. /home/git
[root@centos7 ~]# chmod 700 /home/git
[root@centos7 ~]# chown -R git.git /home/git
9、在 /testdir/dir 里创建的新文件自动属于 webs 组,组 apps 的成员如:tomcat 能对这些新文件有读写权限,组 dbs 的成员如:mysql 只能对新文件有读权限,其它用户(不属于webs,apps,dbs)不能访问这个文件夹
[root@centos7 ~]# groupadd webs
[root@centos7 ~]# groupadd apps
[root@centos7 ~]# groupadd dbs
[root@centos7 ~]# useradd tomcat -g apps
[root@centos7 ~]# useradd mysql -g dbs
[root@centos7 ~]# mkdir -p /testdir/dir
[root@centos7 ~]# chown :webs /testdir/dir/
[root@centos7 ~]# chmod g+s /testdir/dir/
[root@centos7 ~]# chmod o-rwx /testdir/dir/
[root@centos7 ~]# setfacl -d -m g:apps:rw /testdir/dir
[root@centos7 ~]# setfacl -d -m g:dbs:r /testdir/dir
[root@centos7 ~]# setfacl -d -m o::- /testdir/dir
10、备份 /testdir/dir 里所有文件的 ACL 权限到 /root/acl.txt 中,清除 /testdir/dir 中所有 ACL 权限,最后还原 ACL 权限
[root@centos7 /]# getfacl -R /testdir/dir > /root/acl.txt
[root@centos7 /]# setfacl -R -b  /testdir/dir/
[root@centos7 /]# setfacl --set-file=/root/acl.txt /testdir/dir
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值