作业二
1、显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
[15:33:12 root@centos7 etc]#ls -d /etc/[^a-z][a-z][A-Z]*
/etc/1test
2、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
cp -a /etc/p*[[alpha]] /tmp/mytest1/
3、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
tr 'a-z' 'A-Z' < /etc/issue >/tmp/issue.out
4、请总结描述用户和组管理类命令的使用方法并完成以下练习:
(1)、创建组distro,其GID为2019;
[22:27:21 root@centos7 ~]#groupadd -g 2019 distro
(2)、创建用户mandriva, 其ID号为1005;基本组为distro;
[22:31:26 root@centos7 ~]#useradd -u 1005 -g distro mandriv
(3)、创建用户mageia,其ID号为1100,家目录为/home/linux;
[22:34:33 root@centos7 ~]#useradd -u 1100 -d /home/linux mageia
(4)、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
echo "mageedu" | passwd --stdin mageia
passwd -x 7 mageia
(5)、删除mandriva,但保留其家目录;
[22:47:32 root@centos7 ~]#userdel mandriva
[22:47:54 root@centos7 ~]#ll /home/
total 0
drwx------. 3 alex alex 78 Jan 11 15:50 alex
drwx------ 3 mageia mageia 78 Jan 23 22:36 linux
drwx------ 6 mage mage 161 Jan 20 23:58 mage
drwx------ 3 mandriv distro 78 Jan 23 22:33 mandriv
drwx------ 3 1101 1101 78 Jan 23 22:47 mandriva
drwx------ 5 wang wang 180 Jan 20 23:56 wang
(6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
[22:52:47 root@centos7 ~]#useradd -u 2002 -g distro -G peguin slackware
[22:53:11 root@centos7 ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
(7)、修改slackware的默认shell为/bin/tcsh;
[22:53:16 root@centos7 ~]#usermod -s /bin/tcsh slackware
[22:54:14 root@centos7 ~]#tail -1 /etc/passwd
slackware❌2002:2019::/home/slackware:/bin/tcsh
(8)、为用户slackware新增附加组admins,并设置不可登陆。
usermod -G admins -s /sbin/nologin slackware
方法2
usermod -G admins slackware
chsh -s /sbin/nologin slackware
5、创建用户user1、user2、user3。在/data/下创建目录test
[23:00:15 root@centos7 ~]#useradd user1
[23:01:22 root@centos7 ~]#useradd user2
[2[23:01:28 root@centos7 ~]#mkdir /date/test
3:01:25 root@centos7 ~]#useradd user3
(1)、目录/data/test属主、属组为user1
[23:03:32 root@centos7 date]#chown user1:user1 test/
(2)、在目录属主、属组不变的情况下,user2对文件有读写权限
setfacl -m u:user2:rw /data/test/
[23:17:06 root@centos7 date]#getfacl /date/test/
getfacl: Removing leading '/' from absolute path names
file: date/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
[23:18:11 root@centos7 test]#touch a1.sh
[23:18:21 root@centos7 test]#touch a2.sh
[23:18:24 root@centos7 test]#touch a3.sh
[23:18:28 root@centos7 test]#touch a4.sh
[23:28:48 user1@centos7 test]$chmod o+x /date/test/a3.sh /date/test/a4.sh
[23:29:03 user1@centos7 test]$chmod o+t /date/test/a3.sh /date/test/a4.sh
(4)、user3增加附加组user1,同时要求user1不能访问/data/test目录及其下所有文件
usermod -G user3 user1
23:38:25 root@centos7 date]#chmod u=--- /date/test/
[23:38:32 root@centos7 date]#chmod g=--- /date/test/
(5)、清[23:40:22 root@centos7 date]#setfacl -R -b /date/test/理/data/test目录及其下所有文件的acl权限

浙公网安备 33010602011771号