Linux學習第三週練習

一、顯示/etc目錄下,以非字母開頭,後面跟了一個字母以及其它任意長度任意字符的文件或目錄

[root@CentOS8 ~]#find /etc -name "[^[:alpha:]][[:alpha:]]*"
/etc/skel/.bash_logout
/etc/skel/.bash_profile
/etc/skel/.bashrc
/etc/cron.hourly/0anacron
/etc/cron.d/0hourly
/etc/selinux/targeted/.policy.sha512
/etc/.pwd.lock
/etc/.updatedlinux

二、複製/etc下全部以p開頭,以非數字結尾的文件或目錄到/tmp/mytest1目錄

[root@CentOS8 ~]#mkdir /tmp/mytest1
[root@CentOS8 ~]#find /etc -name "p*[^0-9]" ( -type d -o -type f )| xargs -i cp -r {} /tmp/mytest1shell

三、將/etc/issue中的內容轉換爲大寫後保存至/tmp/issue.out文件中

[root@yum-server test2]#cat /etc/issue
\S
Kernel \r on an \mbash

[root@yum-server test2]#cat /etc/issue | tr 'a-z' 'A-Z' >/tmp/issue.out
[root@yum-server test2]#cat /tmp/issue.out
\S
KERNEL \R ON AN \Mide

[root@yum-server test2]#ui

四、請總結描述用戶和組管理類命令的使用方法並完成如下練習:

(1) 建立組distro,其GID爲2019
[root@yum-server ~]#groupadd -g 2019 distro
(2) 建立用戶mandriva,其ID號爲1005;基本組爲distro;
[root@yum-server ~]#useradd -u 1005 -g distro mandriva
[root@yum-server ~]#getent passwd mandriva
mandriva:x:1005:2019::/home/mandriva:/bin/bash
[root@yum-server ~]#id mandriva
uid=1005(mandriva) gid=2019(distro) groups=2019(distro)
(3) 建立用戶mageia,其ID號爲1100,家目錄爲/home/linux;
[root@yum-server ~]#useradd -u 1100 -d /home/linux mageia
[root@yum-server ~]#getent passwd mageia
mageia:x:1100:1100::/home/linux:/bin/bash
[root@yum-server ~]#id mageia
uid=1100(mageia) gid=1100(mageia) groups=1100(mageia)
(4) 給用戶mageia添加密碼,密碼爲mageedu,並設置用戶密碼7天后過時
[root@yum-server ~]#echo "mageedu"|passwd -x 7 --stdin mageia
Adjusting aging data for user mageia.
passwd: Success
[root@yum-server ~]#chage -l mageia
Last password change : Dec 14, 2020
Password expires : Dec 21, 2020
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
[root@yum-server ~]#getent shadow mageia
mageia:!!:18610:0:7:7:::
(5) 刪除mandriva,但保留其家目錄
[root@yum-server ~]#ll /home
total 0
drwx------ 2 mageia mageia 62 Dec 14 10:57 linux
drwx------. 2 lirui lirui 62 Nov 29 23:02 lirui
drwx------ 2 mandriva distro 62 Dec 14 10:55 mandriva
[root@yum-server ~]#userdel mandriva
[root@yum-server ~]#ll /home
total 0
drwx------ 2 mageia mageia 62 Dec 14 10:57 linux
drwx------. 2 lirui lirui 62 Nov 29 23:02 lirui
drwx------ 2 1005 distro 62 Dec 14 10:55 mandriva
[root@yum-server ~]#id mandriva
id: mandriva: no such user
(6) 建立用戶slackware,其ID號爲2002,基本組爲distro,附加組peguin;
[root@yum-server ~]#useradd -u 2002 -g distro -G peguin slackware
[root@yum-server ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
(7) 修改slackware的默認shell爲/bin/tcsh;
[root@yum-server ~]#getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/bash
[root@yum-server ~]#usermod -s /bin/tcsh slackware
[root@yum-server ~]#getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/tcsh
(8) 爲用戶slackware新增附加組admins,並設置不可登陸
[root@yum-server ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
[root@yum-server ~]#getent group admins || groupadd admins;usermod -aG admins -s /sbin/nologin slackware
[root@yum-server ~]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)加密

五、建立用戶user一、user二、user3,在/data下建立目錄/test

(1) 目錄/data/test屬主、屬組爲user1
[root@yum-server ~]#echo user{1..3}|xargs -n1 useradd
[root@yum-server ~]#mkdir -p /data/test
mkdir -p /data/test
chown -R user1:user1 test
(2) 在目錄屬主、屬組不變的狀況下,user2對目錄有讀寫權限
[root@yum-server ~]setfacl -m u:user2:rw- /data/test
[root@yum-server ~]#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
(3) user1在/data/test目錄下建立文件a1.sh,a2.sh,a3.sh,a4.sh,設置全部用戶都不可刪除1.sh、2.sh文件,除了user1及root外,全部用戶都不可刪除a3.sh、a4.sh
[root@yum-server data]#su user1
[user1@yum-server data]$cd test
[user1@yum-server test]$touch a{1..4}.sh
[user1@yum-server test]$ll
total 0
-rw-rw-r-- 1 user1 user1 0 Dec 14 12:23 a1.sh
-rw-rw-r-- 1 user1 user1 0 Dec 14 12:23 a2.sh
-rw-rw-r-- 1 user1 user1 0 Dec 14 12:23 a3.sh
-rw-rw-r-- 1 user1 user1 0 Dec 14 12:23 a4.sh
[root@yum-server test]#chattr +i a1.sh a2.s
[root@yum-server test]#lsattr
----i----------- a1.sh
----i----------- a2.sh
---------------- a3.sh
---------------- a4.sh
[root@yum-server data]#chmod o+t test
[root@yum-server data]#ll -d test
drwxrwxr-t+ 2 user1 user1 58 Dec 14 12:23 test
(4) user3增長附加組user1,同時要求user1不能訪問/data/test目錄及其下全部文件
[root@yum-server test]#id user3
uid=2005(user3) gid=2005(user3) groups=2005(user3)
[root@yum-server test]#usermod -aG user1 user3
[root@yum-server test]#id user3
uid=2005(user3) gid=2005(user3) groups=2005(user3),2003(user1)
[root@yum-server data]#setfacl -m u:user1:- /data/test
[root@yum-server data]#getfacl /data/test
getfacl: Removing leading '/' from absolute path names
file: data/test
owner: user1
group: user1
flags: --t
user::rwx
user:user1:---
user:user2:rw-
group::r-x
mask::rwx
other::r-x
(5) 清理/data/test目錄及其下全部文件的權限
[root@yum-server data]#setfacl -b /data/test*url

相關文章
相關標籤/搜索