第四周 用戶及文件管理練習

第四周 用戶及文件管理練習

練習:

1、複製/etc/skel目錄爲/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。

方法1:
[root@192 \]# cp -r /etc/skel/  /home/tuser1
[root@192 \ ]# chmod -R og= /home/tuser1/
[root@192 skel]# ll
    總用量 32
    -rwx------. 1 root root 24681 3月  29 02:28 123
    -rwx------. 1 root root     5 3月  29 02:28 abc
方法2:
 [root@192 \]# cp -r /etc/skel/  /home/tuser1
 [root@192 skel]# chmod -R  700 /home/tuser1/
 [root@192 skel]# ll
    總用量 32
    -rwx------. 1 root root 24681 3月  29 02:28 123
    -rwx------. 1 root root     5 3月  29 02:28 abc

2、編輯/etc/group文件,添加組hadoop。

[root@192 skel]# vim /etc/group     --手動編輯增加  hadoop:x:2020:
[root@192 skel]# tail -1 /etc/group
                hadoop:x:2020:

3、手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID爲hadoop組的id號;其家目錄爲/home/hadoop。

[root@192 skel]# vim /etc/passwd
[root@192 skel]# tail -1 /etc/passwd
                hadoop:x:102:2020:hadoop:/home/hadoop:/bin/bash

4、複製/etc/skel目錄爲/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒有任何訪問權限。

[root@192 home]# cp -R /etc/skel/  /home/hadoop
[root@192 home]# chmod -R 700  /home/hadoop/
[root@192 home]# ll /home/hadoop/
                總用量 32
                -rwx------. 1 root root 24681 3月  29 03:16 123
                -rwx------. 1 root root     5 3月  29 03:16 abc

5、修改/home/hadoop目錄及其內部所有文件的屬主爲hadoop,屬組爲hadoop。

[root@192 home]# chown hadoop:hadoop hadoop
[root@192 home]# ll -a
                總用量 3372756
                drwxr-xr-x.  6 root     root           94 3月  29 03:16 .
                dr-xr-xr-x. 19 root     root         4096 3月  29 02:04 ..
                drwx------.  2 deplay01 test01         79 3月  29 02:21 deplay01
                drwx------.  2 hadoop   hadoop         79 3月  29 03:16 hadoop
                -rw-r--r--.  1 root     root   3453696911 1月  14 03:25 linuxx64_12201_database.zip
                drwx------.  2 play01   test02         59 3月  29 02:23 play01
                drwx------.  3 root     root           70 3月  29 02:28 tuser1

6、顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用兩種方式。

方法1:    
    [root@192 home]# grep "^[Ss]" /proc/meminfo        --行首錨定
                    SwapCached:            0 kB
                    SwapTotal:       2097148 kB
                    SwapFree:        2097148 kB
                    Shmem:              8844 kB
                    Slab:             145888 kB
                    SReclaimable:      92880 kB
                    SUnreclaim:        53008 kB
方法2:
    [root@192 home]# grep -i "^s" /proc/meminfo         --忽略字符大小寫
                    SwapCached:            0 kB
                    SwapTotal:       2097148 kB
                    SwapFree:        2097148 kB
                    Shmem:              8844 kB
                    Slab:             145888 kB
                    SReclaimable:      92880 kB
                    SUnreclaim:        53008 kB
方法3:
    [root@192 home]# egrep '^(s|S)' /proc/meminfo    --擴展正則表達式
                    SwapCached:            0 kB
                    SwapTotal:       2097148 kB
                    SwapFree:        2097148 kB
                    Shmem:              8844 kB
                    Slab:             145920 kB
                    SReclaimable:      92912 kB
                    SUnreclaim:        53008 kB

7、顯示/etc/passwd文件中其默認shell爲非/sbin/nologin的用戶。

[root@192 home]# grep -v "/sbin/nologin$" /etc/passwd    --行尾錨定
                root:x:0:0:root:/root:/bin/bash
                sync:x:5:0:sync:/sbin:/bin/sync
                shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
                halt:x:7:0:halt:/sbin:/sbin/halt
                deplay01:x:100:2018::/home/deplay01:/bin/bash
                play01:x:101:2019::/home/play01:/bin/bash
                hadoop:x:102:2020:hadoop:/home/hadoop:/bin/bash

8、顯示/etc/passwd文件中其默認shell爲/bin/bash的用戶。

[root@192 home]# grep '/bin/bash$' /etc/passwd

9、找出/etc/passwd文件中的一位數或兩位數。

[root@192 home]# grep -o '\<\([0-9]\{1,2\}\)\>' /etc/passwd
                    3
                    12
                    11

10、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行。

[root@192 grub]# grep "^[[:space:]]\+" /boot/grub/grub.conf 
                 sdsdsds
                  ddddd
                   d1323
                 ssssss
                 fffff
                    SADSAFSAFSAF
                 SDSD
                   @#$%
                 !e~都是

11、顯示/etc/rc.d/rc.local_bak文件中以#開頭,後面跟至少一個空白字符,而後又有至少一個非空白字符的行。

[root@192 rc.d]# grep "^#[[:space:]]\+[^[:space:]]" rc.local_bak
                # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
                # It is highly advisable to create own systemd services or udev rules
                # to run scripts during boot instead of using this file.
                # In contrast to previous versions due to parallel execution during boot
                # this script will NOT be run after all other services.
                #    333
                #  Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
                #   that this script will be executed during boot.

12、打出netstat -tan命令執行結果中以‘LISTEN’,後或跟空白字符結尾的行。

[root@192 rc.d]# netstat -tan |grep 'LISTEN[[:space:]]\+'
                tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
                tcp6       0      0 :::22                   :::*                    LISTEN   

13、添加用戶bash, testbash, basher, nologin (此一個用戶的shell爲/sbin/nologin),而後找出當前系統上其用戶名和默認shell相同的用戶的信息。

     [root@192 rc.d]# useradd testbash
     [root@192 rc.d]# useradd bash
     [root@192 rc.d]# useradd basher
     [root@192 rc.d]# useradd -s /sbin/nologin nologin
     [root@192 rc.d]# grep "^\([^:]\)\+.*\1$" /etc/passwd
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章