练习题

用户组和权限管理
1、创建用户gentoo,附加组为bin和root,默认shell为/bin/csh,注释信息为"Gentoo Distribution"

[root@centos7 ~]# useradd gentoo -G bin,root -s /bin/csh -c “Gentoo Distribution”
[root@centos7 ~]# getent passwd gentoo
gentoo❌1023:1027:Gentoo Distribution:/home/gentoo:/bin/csh

2、创建下面的用户、组和组成员关系 名字为webs 的组 用户nginx 使用webs 作为附属组 用户varnish,也使用webs 作
为附属组 用户mysql,不可交互登录系统,且不是webs 的成员, nginx, varnish, mysql密码都是magedu

[root@centos7 ~]# groupadd webs
[root@centos7 ~]# useradd nginx -G webs
[root@centos7 ~]# useradd varnish -G webs
[root@centos7 ~]# useradd mysql -s /bash/nologin
[root@centos7 ~]# echo “magedu” | passwd --stdin nginx
Changing password for user nginx.
passwd: all authentication tokens updated successfully.
[root@centos7 ~]# echo “magedu” | passwd --stdin varnish
Changing password for user varnish.
passwd: all authentication tokens updated successfully.
[root@centos7 ~]# echo “magedu” | passwd --stdin mysql
Changing password for user mysql.
passwd: all authentication tokens updated successfully.
[root@centos7 ~]# getent passwd nginx varnish mysql
nginx❌1024:1029::/home/nginx:/bin/bash
varnish❌1025:1030::/home/varnish:/bin/bash
mysql❌1026:1031::/home/mysql:/bash/nologin

3、当用户docker对/testdir 目录无执行权限时,意味着无法做哪些操作?#

docker用户无法进入到/testdir目录里,无法移动里面的文件,无法查看文件属性类型
即使又rw权限,也无法查看和修改文件

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

无法用ls列出/testdir目录下的文件列表
可以执行目录内程序
如果对文件又w权限,还可以通过>> 写入文件

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

不能

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

不能修改可以删除

7、复制/etc/fstab文件到/var/tmp下,设置文件所有者为tomcat读写权限,所属组为apps组有读写权限,其他人无权限

[root@centos7 testdir]# cp /etc/fstab /var/tmp
[root@centos7 testdir]# ll /var/tmp/fstab
-rw-r–r-- 1 root root 595 May 19 21:13 /var/tmp/fstab
[root@centos7 testdir]# chown tomcat:apps /var/tmp/fstab
[root@centos7 testdir]# chmod 660 /var/tmp/fstab
[root@centos7 testdir]# ll /var/tmp/fstab
-rw-rw---- 1 tomcat apps 595 May 19 21:13 /var/tmp/fstab

8、误删除了用户git的家目录,请重建并恢复该用户家目录及相应的权限属性

[root@centos7 ~]# cp -r /etc/skel/ /home/git/
[root@centos7 ~]# chown -R git:git /home/git/
[root@centos7 ~]# ll -a /home/git/
total 16
drwxr-xr-x 3 git git 78 May 19 21:19 .
drwxr-xr-x. 26 root root 4096 May 19 21:19 …
-rw-r–r-- 1 git git 18 May 19 21:19 .bash_logout
-rw-r–r-- 1 git git 193 May 19 21:19 .bash_profile
-rw-r–r-- 1 git git 231 May 19 21:19 .bashrc
drwxr-xr-x 4 git git 39 May 19 21:19 .mozilla
[root@centos7 ~]# chmod -R 700 /home/git/

9、在/testdir/dir里创建的新文件自动属于webs组,组apps的成员如:##tomcat能对这些新文件有读写权限,组dbs的
成员如: mysql只能对新文件有读权限,其它用户(不属于webs,apps,dbs)不能访问这个文件夹

[root@centos7 dir]# chgrp -R webs /testdir/dir
[root@centos7 dir]# chmod -R g+s /testdir/dir
[root@centos7 dir]# touch test1
[root@centos7 dir]# ll test1
-rw-r–r-- 1 root webs 0 May 19 21:26 test1

[root@centos7 dir]# usermod -G apps tomcat
[root@centos7 dir]# usermod -G dbs mysql
[root@centos7 dir]# setfacl -R -m g:apps:rw /testdir/dir
[root@centos7 dir]# setfacl -R -m g:dbs:r /testdir/dir
[root@centos7 dir]# setfacl -R -m o::— /testdir/dir

10、备份/testdir/dir里所有文件的ACL权限到/root/acl.txt中,清除/testdir/dir中所有ACL权限,最后还原ACL权限

[root@centos7 dir]# getfacl -R /testdir/dir/ > /root/acl.txt
[root@centos7 dir]# setfacl -R -b /testdir/dir
[root@centos7 dir]# getfacl /testdir/dir
[root@centos7 dir]# setfacl -R --set-file=/root/acl.txt /testdir/dir

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值