学习第三周

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

[root@txcentos7 etc]# touch 15
[root@txcentos7 etc]# touch 1aa
[root@txcentos7 etc]# ls -d /etc/[^[:alpha:]][[:alpha:]]*
/etc/1a  /etc/1aa

二、复制/etc目录下全部以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。linux

[root@txcentos7 tmp]# cp -a /etc/p*[^0-9] /tmp/mytest1/
[root@txcentos7 tmp]# ls /tmp/mytest1/
pam.d   passwd-  plymouth  popt.d   ppp             printcap  profile.d  python
passwd  pki      pm        postfix  prelink.conf.d  profile   protocols

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

[root@txcentos7 tmp]# cat /etc/issue | tr "a-z" "A-Z" >>/tmp/ussue.out
[root@txcentos7 tmp]# cat /tmp/ussue.out
\S
KERNEL \R ON AN \M

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

[root@txcentos7.6 /root]groupadd -g 2019 distro

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

[root@txcentos7.6 /root]useradd mandriva -u 1015 -g distro
[root@txcentos7.6 /root]cat /etc/passwd |egrep mandriva
mandriva:x:1015:2019::/home/mandriva:/bin/bash
[root@txcentos7.6 /root]groups mandriva
mandriva : distro

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

[root@txcentos7 ~]# useradd mageia -d /home/linux -u 1100
[root@txcentos7 ~]# cat /etc/passwd |egrep mageia
mageia:x:1100:1100::/home/linux:/bin/bash
[root@txcentos7 home]# ls /home
linux  mandriva  tommy  tt  username  wang  wang1  wwwww

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

[root@txcentos7 home]# echo mageedu | passwd --stdin  mageia
Changing password for user mageia.
passwd: all authentication tokens updated successfully.
[root@txcentos7 home]# passwd mageia -x 7
Adjusting aging data for user mageia.
passwd: Success
#列出密码有效期:
[root@txcentos7 home]# chage -l mageia
Last password change                                    : Mar 22, 2021
Password expires                                        : Mar 29, 2021
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 7
Number of days of warning before password expires       : 7

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

[root@txcentos7 home]# userdel mageia

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

[root@txcentos7 home]# groupadd peguin
[root@txcentos7 home]# useradd slackware -u 2002 -g distro -G peguin
[root@txcentos7 home]# groups slackware
slackware : distro peguin

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

[root@txcentos7 home]# usermod -s /bin/tcsh slackware
[root@txcentos7 home]# cat /etc/passwd | egrep slackware
slackware:x:2002:2019::/home/slackware:/bin/tcsh

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

[root@txcentos7 home]# id  slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)

[root@txcentos7 sbin]# usermod slackware -s /sbin/nologin
[root@txcentos7 sbin]# echo mageedu | passwd --stdin slackware
Changing password for user slackware.
passwd: all authentication tokens updated successfully.
WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Mon Mar 22 22:02:57 2021 from 111.196.233.254
This account is currently not available.
Connection closing...Socket close.

Connection closed by foreign host.

五、建立用户user一、user二、user3。在/data/下建立目录test

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

[root@txcentos7 data]# chown user1:user1 test
[root@txcentos7 data]# ll -t
total 28
drwxr-xr-x 2 user1 user1 4096 Mar 22 22:05 test

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

[root@txcentos7 data]# chmod o+rw test
[root@txcentos7 data]# ll -t
total 28
drwxr-xrwx 2 user1 user1 4096 Mar 22 22:05 test

[root@txcentos7 data]# su user2
[user2@txcentos7 data]$ cd /data/
[user2@txcentos7 data]$ ls
1111  laji  lajixiang  nianling.txt  script  test  vkokdfs
[user2@txcentos7 data]$ cd test/
[user2@txcentos7 test]$ touch 10.txt
[user2@txcentos7 test]$ ll
total 0
-rw-rw-r-- 1 user2 user2 0 Mar 22 22:11 10.txt

(3)、user1在/data/test目录下建立文件a1.sh, a2.sh, a3.sh, a4.sh,设置全部用户都不可删除1.sh,2.sh文件、除了user1及root以外,全部用户都不可删除a3.sh, a4.sh

[user1@txcentos7 test]$ touch a{1..4}\.sh
[user1@txcentos7 test]$ ls
a1.sh  a2.sh  a3.sh  a4.sh

设置全部用户不可删除时普通用户没法执行cahttr +i命令,是否有其余方法?
[root@txcentos7 test]# chattr +i a1.sh
[root@txcentos7 test]# chattr +i a2.sh
[root@txcentos7 test]# lsattr
-------------e-- ./a3.sh
-------------e-- ./a4.sh
----i--------e-- ./a1.sh
----i--------e-- ./a2.sh

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

[root@txcentos7 test]# usermod user3 -aG user1
[root@txcentos7 test]# id user3
uid=2006(user3) gid=2006(user3) groups=2006(user3),2004(user1)

setfacl -m u:user1:- /data/test/
[root@txcentos7 test]# su user1
[user1@txcentos7 test]$ cd /data/test/
bash: cd: /data/test/: Permission denied


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

[root@txcentos7 test]# setfacl -R -b /data/test/
相关文章
相关标签/搜索