第二周作业


二、第二周作业

1、显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录。

[root@centos7 ~]# ll -d /etc/[^[:alpha:][[:alpha:]]*

2、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中

[root@centos7 ~]# mkdir -p /tmp/mytest1
[root@centos7 mytest1]# cp -ar p*[^[:digit:]] /tmp/mytest1

3、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中

[root@centos7 ~]# cat /etc/issue
jintianshigehaotianqiS
Kernel \r on an \m
[root@centos7 ~]# cat /etc/issue | tr 'a-z' 'A-Z' >/tmp/issue.out
[root@centos7 tmp]# cat issue.out

4、请总结描述用户和组管理类命令的使用方法并完成以下练习: (1)、创建组distro,其GID为2019;

[root@centos7 ~]# groupadd -g 2019 distro
[root@centos7 ~]# getent group distro
distro:x:2019:

(2)、创建用户mandriva, 其ID号为1005;基本组为distro;

[root@centos7 ~]# useradd -u 1005 -g distro mandriva
[root@centos7 ~]# id mandriva
uid=1005(mandriva) gid=2019(distro) groups=2019(distro)

(3)、创建用户mageia,其ID号为1100,家目录为/home/linux;

[root@centos7 ~]# useradd -o -u 1100 -d /home/linux mageia
[root@centos7 ~]# id mageia
uid=1100(mageia) gid=1100(mageia) groups=1100(mageia)

(4)、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期

[root@centos7 ~]# passwd mageia
Changing password for user mageia.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@centos7 ~]# getent shadow mageia
mageia:$6$Bgmqw2Tk$bxZXsUhzdJ5s1Llp8Kv8wxV.FHDkmjrO1YoTO/zHkLRwl9vm0WbDqNXmCErDTE2RW16psfQm.B5re6ANK/70.0:19066:0:99999:7:::
[root@centos7 ~]# chage -E 7 mageia
[root@centos7 ~]# getent shadow mageia
mageia:$6$Bgmqw2Tk$bxZXsUhzdJ5s1Llp8Kv8wxV.FHDkmjrO1YoTO/zHkLRwl9vm0WbDqNXmCErDTE2RW16psfQm.B5re6ANK/70.0:19066:0:99999:7::7:

(5)、删除mandriva,但保留其家目录;

[root@centos7 ~]# userdel mandriva
[root@centos7 ~]# ls /home
mandriva wu

(6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;

[root@centos7 ~]# groupadd peguin
[root@centos7 ~]# useradd -o -u 2002 -g distro -G peguin slackware
[root@centos7 ~]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)

(7)、修改slackware的默认shell为/bin/tcsh;

[root@centos7 ~]# usermod -s /bin/tcsh slackware
[root@centos7 ~]# getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/tcsh

(8)、为用户slackware新增附加组admins,并设置不可登陆。

[root@centos7 ~]# usermod -a -G admins -s /bin/nologin slackware

5、创建用户user1、user2、user3。在/data/下创建目录test

[root@centos7 ~]# useradd user1;useradd user2;useradd user3;mkdir /data/test
[root@centos7 ~]# ll /home
total 0
drwx------ 3     1005 distro 78 Mar 15 10:50 mandriva
drwx------ 3 slackware distro 94 Mar 15 11:29 slackware
drwx------ 3 user1     user1   78 Mar 15 12:01 user1
drwx------ 3 user2     user2   78 Mar 15 12:01 user2
drwx------ 3 user3     user3   78 Mar 15 12:01 user3
drwx------. 5 wu       wu     161 Mar 9 22:02 wu
[root@centos7 ~]# ll /data
total 4
-rw-r--r--. 1 root root 11 Mar 8 17:49 123.txt
-rw-r--r--. 1 root root 0 Mar 8 16:55 a.zip
-rw-r--r--. 1 root root 0 Mar 9 22:43 dir
drwxr-xr-x 2 root root 6 Mar 15 12:01 test

(1)、目录/data/test属主、属组为user1

drwxr-xr-x 2 root root 6 Mar 15 12:17 /data/test
[root@centos7 /]# chown user1.user1 /data/test
[root@centos7 /]# ll -d /data/test
drwxr-xr-x 2 user1 user1 6 Mar 15 12:17 /data/test

(2)、在目录属主、属组不变的情况下,user2对文件有读写权限

[root@centos7 data]# setfacl -m u:user2:rw test
[root@centos7 data]# getfacl test
# file: test
# owner: user1
# group: user1
user::rwx
user:user2:rw-
group::r-x
mask::rwx
other::r-x

(3)、user1在/data/test目录下创建文件a1.sh, a2.sh, a3.sh, a4.sh,设置所有用

户都不可删除1.sh,2.sh文件、除了user1及root之外,所有用户都不可删除a3.sh, a4.sh

[root@centos7 data]# touch test/a{1..4}.sh
[root@centos7 data]# ls test
a1.sh a2.sh a3.sh a4.sh
[root@centos7 data]# cd test
[root@centos7 test]# chattr +i a1.sh
[root@centos7 test]# chattr +i a2.sh
[root@centos7 test]# lsattr a1.sh
----i----------- a1.sh
[root@centos7 test]# lsattr a1.sh a2.sh
----i----------- a1.sh
----i----------- a2.sh
[root@centos7 test]# chmod o+t /data/test/a3.sh /data/test/a4.sh

(4)、user3增加附加组user1,同时要求user1不能访问/data/test目录及其下所有文件

[root@centos7 test]# usermod -a -G user1 user3
[root@centos7 test]# setfacl -m u:user1:- /data/test
[root@centos7 test]# getfacl /data/test
getfacl: Removing leading '/' from absolute path names
# file: data/test
# owner: user1
# group: user1
user::rwx
user:bin:---
user:user1:---
user:user2:rw-
group::r-x
mask::rwx
other::r-x

(5)、清理/data/test目录及其下所有文件的acl权限

[root@centos7 test]# setfacl -R -b /data/test
[root@centos7 test]# getfacl /data/test
getfacl: Removing leading '/' from absolute path names
# file: data/test
# owner: user1
# group: user1
user::rwx
group::r-x
other::r-x

 

相关