第三周作業(yè)

1、顯示/etc目錄下,以非字母開頭,后面跟了一個(gè)字母以及其他任意長度任意字符的文件或目錄
[root@centos7]# ls /etc/|grep "^[^[:alpha:]][[:alpha:]].*"

2、復(fù)制/etc目錄下所有以p開頭,以非數(shù)字結(jié)尾的文件或目錄到/tmp/mytest1目錄中。
[root@centos7]# mkdir -p /tmp/mytest1
[root@centos7]# ls | grep '^p.*[^[:digit:]]$' | xargs -i cp -a {} /tmp/mytest1/

3、將/etc/issue文件中的內(nèi)容轉(zhuǎn)換為大寫后保存值/tmp/issue.out文件中
[root@centos7]# cat /etc/issue | tr 'a-z' 'A-Z' > /tmp/issue.out

4、請(qǐng)總結(jié)描述用戶和組管理類命令的使用方法并完成以下練習(xí)
4.1 用戶和組管理類命令的使用方法:
4.1.1 用戶的增刪改命令
1)增加永固命令
useradd [option] LOGIN
2)刪除用戶命令
userdel [option] LOGIN
3)更改用戶屬性命令
usermod [option] LOGIN
4.1.2 組的增刪改命令
1)增加組命令
groupadd [options] GROUP
2)刪除組命令
groupdel [option] GROUP
3)修改組命令
groupmod [option] GROUP
4.1.3 其他用戶管理命令
1)修改用戶密碼類策略
chage [options] LOGIN
2)指定個(gè)人信息
chfn [options] [username]
3)指定用戶shell類型
chsh [options] [username]
4)切換用戶身份
su [options] [-] [USER [arg]...]
(1)、創(chuàng)建組distro,其GID為2019;
[root@centos7]# groupadd -g 2019 distro

[root@centos7]# getent group distro
distro:x:2019:
(2)、創(chuàng)建用戶mandriva,其ID號(hào)為1005;基本組為distro;
[root@centos7]# useradd -u 1005 -g distro mandriva
[root@centos7]# id mandriva
uid=1005(mandriva) gid=2019(distro) groups=2019(distro)
(3)、創(chuàng)建用戶mageia,其ID為1100.家目錄為/home/linux;
[root@centos7]# useradd -u 1100 -d /home/linux mageia
[root@centos7]# ls /home | grep linux
linux
[root@centos7]#id mageia
uid=1100(mageia) gid=1100(mageia) groups=1100(mageia)
(4)、給用戶mageia添加密碼,密碼為mageedu,并設(shè)置用戶密碼7天后過期
[root@centos7]# useradd mageia
[root@centos7]# echo "mageedu" | passwd --stdin mageia
Changing password for user mageia.
passwd: all authentication tokens updated successfully.
[root@centos7]# chage -E 7 mageia
[root@centos7]# cat /etc/shadow | grep mageia
mageia:$6$icm2RmLB$npbF.KDu3wgbMezW3Nyj33CxakYkgmRO3NE0LaB365KhBna52GmymqlsSbX/zEEffET1JwfY23OwYtBPSIlwM0:18686:0:99999:7::7:
(5)、刪除mandriva,但保留其家目錄;
[root@centos7]# userdel mandriva
[root@centos7]# ls /home/ | grep linux
linux
(6)、創(chuàng)建用戶slackware,其ID號(hào)為2002,基本組為distro,附加組peguin;
[root@centos7]# groupadd peguin
[root@centos7]# useradd -u 2002 -g distro -G peguin slackware
[root@centos7]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
(7)、修改slackware的默認(rèn)shell為/bin/tcsh;
[root@centos7]# usermod -s /bin/tcsh slackware
[root@centos7]# getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/tcsh
(8)、為用戶slackware新增加附加組admins,并設(shè)置不可登錄;
[root@centos7]# groupadd admins
[root@centos7]# getent group admins
admins:x:2021:
[root@centos7]# usermod -G peguin,admins slackware
[root@centos7]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)
[root@centos7]# chsh slackware -s /sbin/nologin
Changing shell for slackware.
Shell changed.
[root@centos7]# getent passwd slackware
slackware:x:2002:2019::/home/slackware:/sbin/nologin

5、創(chuàng)建用戶user1、user2、user3,在/data/下創(chuàng)建目錄test
[root@centos7]# useradd user1
[root@centos7]# useradd user2
[root@centos7]# useradd user3
[root@centos7]# mkdir -p /data/test
(1)、目錄/data/test屬主、屬組為user1
[root@centos7]# chown user1.user1 /data/test/
[root@centos7]# ll /data
total 0
drwxr-xr-x. 2 user1 user1 6 Feb 28 22:03 test
(2)、在目錄屬主、屬組不變的情況下,user2對(duì)文件有讀寫權(quán)限
[root@centos7]# setfacl -m u:user2:rw /data/test/
[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
(3)、user1在/data/test目錄下創(chuàng)建文件a1.sh,a2.sh,a3.sh,a4.sh,設(shè)置所有用戶都不可刪除a1.sh,a2.sh文件、除了user1及root之外,所有用戶都不可刪除a3.sh,a4.sh
[root@centos7]# su - user1
[root@centos7]# touch /data/test/a{1..4}.sh
[root@centos7]# ls /data/test/
a1.sh a2.sh a3.sh a4.sh
[root@centos7]# chattr +i /data/test/a1.sh /data/test/a2.sh
chattr: Operation not permitted while setting flags on /data/test/a1.sh
chattr: Operation not permitted while setting flags on /data/test/a2.sh
[root@centos7]# chmod o+t /data/test/a3.sh /data/test/a4.sh
(4)、user3增加附加組user1,同時(shí)要求user1不能訪問/data/test目錄及其下所有文件
[root@centos7]# usermod user3 -a -G user1
[root@centos7]# id user3
uid=2005(user3) gid=2005(user3) groups=2005(user3),2003(user1)
[root@centos7]# setfacl -m u:user1:- /data/test/
(5)、清理/data/test目錄下及其下所有文件的acl權(quán)限
[root@centos7]# setfacl -R -b /data/test/
[root@centos7]# 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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 題目1.顯示/etc目錄下,以非字母開頭,后面跟了一個(gè)字母以及其他任意長度任意字符的文件或目錄。 解答: ls /...
    Easy_8195閱讀 246評(píng)論 0 0
  • 1、顯示/etc目錄下,以非字母開頭,后面跟了一個(gè)字母以及其它任意長度任意字符的文件或目錄 [11:40:51 r...
    陌路殘蟬閱讀 263評(píng)論 0 0
  • 顯示/etc目錄下,以非字母開頭,后面跟了一個(gè)字母以及其他任意長度任意字符的文件或目錄 ls /etc/ | gr...
    紫火紅云閱讀 293評(píng)論 0 0
  • 1、顯示/etc目錄下,以非字母開頭,后面跟了一個(gè)字母以及其他任意長度任意字符的文件或目錄 2、復(fù)制/etc目錄下...
    阿杜ddq閱讀 644評(píng)論 0 0
  • 1、顯示/etc目錄下,以非字母開頭,后面跟了一個(gè)字母以及其它任意長度任意字符的文件或目錄 [12:01:24 r...
    196_fendou閱讀 241評(píng)論 0 0

友情鏈接更多精彩內(nèi)容