第三周

1. 顯示/etc目錄下,以非字母開頭,后面跟了一個(gè)字母以及其他任意長度任意字符的文件或目錄。

root@centos8 etc]$ls /etc/[^[:alpha:]][[:alpha:]]*
ls: cannot access '/etc/[^[:alpha:]][[:alpha:]]*': No such file or directory
[root@centos8 etc]$ls /data/[^[:alpha:]][[:alpha:]]*
/data/2a3443fdeb.txt

/data/2adir:
[root@centos8 etc]$

2.復(fù)制/etc目錄下所有以p開頭,以非數(shù)字結(jié)尾的文件或目錄到/tmp/mytest目錄中。

[root@centos8 etc]$cp -r /etc/p*[^[:digit:]] /tmp/mytest1
[root@centos8 etc]$ls /tmp/mytest1/
pam.d  passwd  passwd-  pki  plymouth  pm  popt.d  prelink.conf.d  printcap  profile  profile.d  protocols

3. 將/etc/issue文件中的內(nèi)容轉(zhuǎn)換為大寫后保存至/tmp/issue.out文件中。

[root@centos8 etc]$cat /etc/issue
\S
Kernel \r on an \m
terminal: \l 
hostname: \m 
time: \t 

The server will shutdown at 18:30 today

[root@centos8 etc]$cat /etc/issue|tr 'a-z' 'A-Z' >/tmp/issue.out
[root@centos8 etc]$cat /tmp/issue.out 
\S
KERNEL \R ON AN \M
TERMINAL: \L 
HOSTNAME: \M 
TIME: \T 

THE SERVER WILL SHUTDOWN AT 18:30 TODAY

4. 請總結(jié)描述用戶和組管理類命令的使用方法并完成以下練習(xí):

  • useradd 添加用戶
  • usermod 修改用戶屬性
  • passwd 設(shè)置用戶密碼
  • chage 設(shè)置用戶密碼策略
  • groupadd 添加組
  • gpasswd 設(shè)置組密碼
  • groupmems 設(shè)置組成員信息
  • groupmod 修改用戶屬性
  • chpasswd 設(shè)置用戶密碼

(1),創(chuàng)建組distro,其GID為2019

[root@centos8 etc]$groupadd -g 2019 distro
[root@centos8 etc]$getent group distro
distro:x:2019:

(2),創(chuàng)建用戶mandriva,其ID號(hào)為1005,基本組為distro

[root@centos8 etc]$useradd -u 1005 -g distro mandriva
[root@centos8 etc]$getent passwd mandriva
mandriva:x:1005:2019::/home/mandriva:/bin/bash

(3),創(chuàng)建用戶mageia,其ID號(hào)為1100,家目錄為/home/linux

[root@centos8 etc]$useradd -u 1100 -d /home/linux mageia
[root@centos8 etc]$getent passwd mageia
mageia:x:1100:1100::/home/linux:/bin/bash
[root@centos8 etc]$

(4),給用戶mageia添加密碼,密碼為mageedu,并設(shè)置用戶密碼7天后過期

[root@centos8 etc]$echo mageedu|passwd --stdin mageia
Changing password for user mageia.
passwd: all authentication tokens updated successfully.

[root@centos8 etc]$chage -M 7 mageia
[root@centos8 etc]$chage -l mageia
Last password change                    : Dec 08, 2020
Password expires                    : Dec 15, 2020
Password inactive                   : Dec 22, 2020
Account expires                     : Mar 18, 2021
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,并保留其家目錄;

[root@centos8 etc]$userdel mandriva
[root@centos8 etc]$ls -al /home/mandriva/
total 12
drwx------  2 1005 distro  62 Dec  8 09:51 .
drwxr-xr-x. 9 root root   102 Dec  8 09:51 ..
-rw-r--r--  1 1005 distro  18 Nov  9  2019 .bash_logout
-rw-r--r--  1 1005 distro 141 Nov  9  2019 .bash_profile
-rw-r--r--  1 1005 distro 312 Nov  9  2019 .bashrc

(6)創(chuàng)建用戶slackware,其ID號(hào)為2002,基本組為distro,附加組peguin,

[root@centos8 etc]$useradd -u 2002 -g distro -G peguin slackware
[root@centos8 etc]$id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)

(7),修改slackware默認(rèn)shell為/bin/tcsh

[root@centos8 etc]$usermod -s /bin/tcsh slackware
[root@centos8 etc]$getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/tcsh

(8),為用戶slackware新增附加組admins,并設(shè)置不可登錄。

[root@centos8 etc]$groupadd admins
[root@centos8 etc]$usermod -aG admins -s /sbin/nologin slackware
[root@centos8 etc]$id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)
[root@centos8 etc]$getent passwd slackware
slackware:x:2002:2019::/home/slackware:/sbin/nologin

5,創(chuàng)建用戶user1,user2,user3。在/data下創(chuàng)建目錄test

[root@centos8 etc]$useradd user1
[root@centos8 etc]$useradd user2
[root@centos8 etc]$useradd user3
[root@centos8 etc]$rm -rf /data/*
[root@centos8 etc]$mkdir /data/test
[root@centos8 etc]$

(1),目錄/data/test屬主,屬組為user1,

[root@centos8 etc]$chown  user1:user1 /data/test
[root@centos8 etc]$ll -ad /data/test
drwxr-xr-x 2 user1 user1 6 Dec  8 10:26 /data/test

(2),在目錄屬主,屬組不變的情況下,user2對文件有讀寫權(quán)限。

[root@centos8 etc]$setfacl -m g:user2:wr /data/test
[root@centos8 etc]$getfacl /data/test
getfacl: Removing leading '/' from absolute path names
# file: data/test
# owner: user1
# group: user1
user::rwx
group::r-x
group:user2:rw-
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@centos8 etc]$chattr  +i /data/test/a{1,2}.sh
[root@centos8 etc]$lsattr  /data/test/a{1,2}.sh
----i-------------- /data/test/a1.sh
----i-------------- /data/test/a2.sh
[root@centos8 etc]$rm /data/test/a1.sh
rm: remove regular empty file '/data/test/a1.sh'? y
rm: cannot remove '/data/test/a1.sh': Operation not permitted

[root@centos8 etc]$chmod o+t /data/test
[root@centos8 etc]$ls -dl /data/test
drwxrwxr-t+ 2 user1 user1 58 Dec  8 10:33 /data/test

(4),user3增加附加組user1,同時(shí)要求user1不能訪問/data/test目錄下及其下所有文件

[root@centos8 etc]$id user3
uid=2005(user3) gid=2005(user3) groups=2005(user3),2003(user1)

[root@centos8 etc]$setfacl -m g:user1:- /data/test
[root@centos8 etc]$getfacl /data/test
getfacl: Removing leading '/' from absolute path names
# file: data/test
# owner: user1
# group: user1
# flags: --t
user::rwx
group::r-x
group:user1:---
group:user2:rw-
mask::rwx
other::r-x


(5), 清理/data/test目錄及其下所有文acl權(quán)限

[root@centos8 etc]$setfacl -b /data/test
[root@centos8 etc]$getfacl /data/test
getfacl: Removing leading '/' from absolute path names
# file: data/test
# owner: user1
# group: user1
# flags: --t
user::rwx
group::r-x
other::r-x

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

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

  • Q1、顯示/etc目錄下,以非字母開頭,后面跟了一個(gè)字母以及其它任意長度任意字符的文件或目錄 Q2、復(fù)制/etc目...
    Liang_JC閱讀 282評論 0 0
  • 1、顯示/etc目錄下,以非字母開頭,后面跟了一個(gè)字母以及其它任意長度任意字符的文件或目錄。 命令如下: 執(zhí)行命令...
    82bb6438ec05閱讀 240評論 0 1
  • Q1:顯示/etc目錄下,以非字母開頭,后面跟了一個(gè)字母以及其它任意長度任意字符的文件或目錄A1:ls -dl |...
    丹楓_Nariss閱讀 242評論 0 0
  • 一、顯示/etc目錄下,以非字母開頭,后面跟了一個(gè)字母以及其它任意長度任意字符的文件或目錄 [root@cento...
    Gustav_man閱讀 300評論 0 0
  • 1、顯示/etc目錄下,以非字母開頭,后面跟了一個(gè)字母以及其它任意長度任意字符的文件或目錄 或是 2、復(fù)制/etc...
    歸來兮_007閱讀 254評論 0 0

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