一、顯示/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/