0
点赞
收藏
分享

微信扫一扫

第二周 作业 学号:N63004

代码敲到深夜 2022-03-11 阅读 36

第二周
1、显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录 
2、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
3、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
4、请总结描述用户和组管理类命令的使用方法并完成以下练习:
(1)、创建组distro,其GID为2019;
(2)、创建用户mandriva, 其ID号为1005;基本组为distro;
(3)、创建用户mageia,其ID号为1100,家目录为/home/linux;
(4)、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
(5)、删除mandriva,但保留其家目录;
(6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
(7)、修改slackware的默认shell为/bin/tcsh;
(8)、为用户slackware新增附加组admins,并设置不可登陆。
5、创建用户user1、user2、user3。在/data/下创建目录test
(1)、目录/data/test属主、属组为user1
(2)、在目录属主、属组不变的情况下,user2对文件有读写权限
(3)、user1在/data/test目录下创建文件a1.sh, a2.sh, a3.sh, a4.sh,设置所有用户都不可删除1.sh,2.sh文件、除了user1及root之外,所有用户都不可删除a3.sh, a4.sh
(4)、user3增加附加组user1,同时要求user1不能访问/data/test目录及其下所有文件
(5)、清理/data/test目录及其下所有文件的acl权限

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

 [11:45:50 root@centos7[ etc]#ls  /etc/ | grep ^[^[:alpha:]][[:alpha:]].*

 

[13:38:11 root@centos7[ etc]#ls  /etc/ | grep ^[^[:alpha:]]

 

[13:42:19 root@centos7[ etc]#ls  /etc/ | grep ^[^[:lower:]]

 

附:[:alpha:]  字母
[:digtal:]  数字
[:lower:]  小写
[:upper:]  大写
[:alnum:]  字母和数字
[:space:]   空白字符
[:punct:]   标点特殊字符

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

[13:46:54 root@centos7[ /]#mkdir /tmp/mytest1

[13:49:08 root@centos7[ /]#cd /tmp/mytest1

[13:49:25 root@centos7[ mytest1]#cp -r /etc/p*[^0-9]  /tmp/mytest1/

[13:50:42 root@centos7[ mytest1]#ls

pam.d   passwd-  plymouth  popt.d   ppp             printcap  profile.d  python

passwd  pki      pm        postfix  prelink.conf.d  profile   protocols

[13:53:41 root@centos7[ /]#cat /etc/issue  |  tr 'a-z' 'A-Z' > /tmp/issue.out

[13:53:50 root@centos7[ /]#cat /tmp/issue.out

\S

KERNEL \R ON AN \M

[13:54:08 root@centos7[ /]#cat /etc/issue

\S

Kernel \r on an \m

创建组distro,其GID为2019

[13:54:39 root@centos7[ /]# groupadd  -g  2019  distro

 

[13:58:08 root@centos7[ /]#getent group distro

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

 

[14:01:57 root@centos7[ /]#useradd -u 1100 -d /home/linux  mageia

[14:03:03 root@centos7[ /]#ll -a /home/linux

total 12

drwx------. 2 mageia mageia  62 Feb 24 14:03 .

drwxr-xr-x. 5 root   root    48 Feb 24 14:03 ..

-rw-r--r--. 1 mageia mageia  18 Aug  8  2019 .bash_logout

-rw-r--r--. 1 mageia mageia 193 Aug  8  2019 .bash_profile

-rw-r--r--. 1 mageia mageia 231 Aug  8  2019 .bashrc

 

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

[14:07:47 root@centos7[ /]#echo mageedu  | passwd -x  7  --stdin  mageia

Adjusting aging data for user mageia.

passwd: Success

 

[14:08:29 root@centos7[ /]#getent shadow  mageia

删除mandriva,但保留其家目录

[root@centos7 ~]# userdel mandriva

[root@centos7 ~]# ls /home/

linux  mandriva  zhang

 

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

[root@centos7 ~]# groupadd peiguin

[root@centos7 ~]# useradd slackware -u 2002 -g distro -G peiguin

[root@centos7 ~]# id slackware

uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peiguin)

 

修改slackware的默认shell为/bin/tcsh;

[root@centos7 ~]# getent passwd slackware

slackware:x:2002:2019::/home/slackware:/bin/bash

[root@centos7 ~]# groupadd admins

[root@centos7 ~]# usermod -a -G admins slackware

[root@centos7 ~]# id slackware

uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peiguin),2021(admins)

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

[14:15:30 root@centos7[ /]#useradd user1;useradd user2;useradd suer3; mkdir /data/test

 

[14:24:02 root@centos7[ /]#useradd user1;useradd user2;useradd user3; mkdir /data/test

useradd: user 'user1' already exists

useradd: user 'user2' already exists

mkdir: cannot create directory ‘/data/test’: File exists

[14:24:18 root@centos7[ /]#ll /etc/passwd |grep user*

[14:24:51 root@centos7[ /]#cat /etc/passwd | grep user*

user1:x:1101:1101::/home/user1:/bin/bash

user2:x:1102:1102::/home/user2:/bin/bash

user3:x:1104:1104::/home/user3:/bin/bash

目录/data/test属主、属组为user1

[14:25:06 root@centos7[ /]#ll -d /data/test

drwxr-xr-x. 2 root root 6 Feb 24 14:19 /data/test

[14:26:08 root@centos7[ /]#chown user1 /data/test ; chgrp user1 /data/test

[14:27:35 root@centos7[ /]#ll -d /data/test

drwxr-xr-x. 2 user1 user1 6 Feb 24 14:19 /data/test

 

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

[14:30:41 root@centos7[ /]#setfacl -R -m u:user2:rw /data/test

[14:31:09 root@centos7[ /]#getfacl /data/test

getfacl: Removing leading '/' from absolute path names

# file: data/test

# owner: user1

# group: user1

user::rwx

user:user2:rw-

group::r-x

mask::rwx

other::r-x

 

user1在/data/test目录下创建文件a1.sh, a2.sh, a3.sh, a4.sh,设置所有用户都不可删除1.sh,2.sh文件、除了user1及root之外,所有用户都不可删除a3.sh, a4.sh

[14:31:29 root@centos7[ /]#cd /data/test

[14:33:44 root@centos7[ test]#pwd

/data/test

[14:33:45 root@centos7[ test]#touch a{1..4}.sh

[14:34:08 root@centos7[ test]#chattr a1.sh a2.sh

Must use '-v', =, - or +

[14:34:45 root@centos7[ test]#chattr +i a1.sh a2.sh

[14:35:06 root@centos7[ test]#lsattr

----i----------- ./a1.sh

----i----------- ./a2.sh

---------------- ./a3.sh

---------------- ./a4.sh

 

[14:35:35 root@centos7[ test]#chmod o+t a3.sh a4.sh

[14:37:01 root@centos7[ test]#ll

total 0

-rw-r--r--. 1 root root 0 Feb 24 14:34 a1.sh

-rw-r--r--. 1 root root 0 Feb 24 14:34 a2.sh

-rw-r--r-T. 1 root root 0 Feb 24 14:34 a3.sh

-rw-r--r-T. 1 root root 0 Feb 24 14:34 a4.sh

 

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

[14:37:03 root@centos7[ test]#id user3

uid=1104(user3) gid=1104(user3) groups=1104(user3)

[14:38:54 root@centos7[ test]#usermod -G user1 user3

[14:39:37 root@centos7[ test]#id user3

uid=1104(user3) gid=1104(user3) groups=1104(user3),1101(user1)

 

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

[14:39:43 root@centos7[ test]#getfacl /data/test

getfacl: Removing leading '/' from absolute path names

# file: data/test

# owner: user1

# group: user1

user::rwx

user:user2:rw-

group::r-x

mask::rwx

other::r-x

[14:41:35 root@centos7[ test]#setfacl -R -b /data/test

[14:42:00 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

 

举报

相关推荐

第二周作业

JSP第二周作业

马哥教育 第二周作业

第二周

假期第二周

0 条评论