馬哥教育網絡班21期+第4周課程練習
[TOC]
1. 復制/etc/skel目錄為/home/tuser1,要求/home/tuser1*及其內部文件的屬組和其他用戶均沒有任何訪問權限。
[root@rhel-5 ~]# cp -rf /etc/skel/ /home/tuser1 [root@rhel-5 ~]# chown -R go-rwx /home/tuser1/ drwx------ 4 root root 4096 07-31 18:58 /home/tuser1/
2. 編輯/etc/group文件,添加組hadoop。
[root@rhel-5 tuser1]# grep 'hadoop' /etc/group hadoop:x:503:
3.手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop的id號;其家目錄為/home/hadoop。
[root@rhel-5 tuser1]# grep 'hadoop' /etc/passwd hadoop:x:501:503::/home/hadoop:/bin/bash
4. 復制/etc/skel目錄為/home/hadoop,要求修改hadoop*目錄的屬組和其他用戶沒有任何訪問權限。
[root@rhel-5 tuser1]# cp -rf /etc/skel/ /home/hadoop [root@rhel-5 tuser1]# chmod -R go-rwx /home/hadoop/
5. 修改/home/hadoop目錄及其內部所有文件的屬主為hadoop,屬組為hadoop。
[root@rhel-5 tuser1]# chown -R hadoop:hadoop /home/hadoop/ [root@rhel-5 tuser1]# chown -R hadoop.hadoop /home/hadoop/
6. 顯示/proc/meminfo文件中以大寫或小寫s開頭的行,用三種方式。
[root@rhel-5 tuser1]# grep '^[Ss]' /proc/meminfo SwapCached: 115456 kB SwapTotal: 2096472 kB SwapFree: 1752576 kB Slab: 37600 kB [root@rhel-5 tuser1]# grep '^\(S\|s\)' /proc/meminfo SwapCached: 115488 kB SwapTotal: 2096472 kB SwapFree: 1752588 kB Slab: 37596 kB [root@rhel-5 tuser1]# grep -i '^s' /proc/meminfo SwapCached: 116356 kB SwapTotal: 2096472 kB SwapFree: 1752600 kB Slab: 37568 kB
7. 顯示/etc/passwd文件中默認shell為非/sbin/nologin的用戶。
[root@rhel-5 tuser1]# grep '\/sbin\/nologin\>$' /etc/passwd
8. 顯示/etc/passwd文件中默認shell為/bin/bash的用戶。
[root@rhel-5 tuser1]# grep '\/bin\/bash\>$' /etc/passwd root:x:0:0:root:/root:/bin/bash oracle:x:500:500::/home/oracle:/bin/bash hadoop:x:501:503::/home/hadoop:/bin/bash
9. 找出/etc/passed文件中的一位數或兩位數。
[root@rhel-5 tuser1]# grep -wE '[0-9]{1,2}' /etc/passwd [root@rhel-5 tuser1]# grep -E '\<[0-9]{1,2}\>' /etc/passwd
10. 顯示/boot/grub/grub.conf中至少以一個空白字符開頭的行。
[root@rhel-5 tuser1]# grep -E '^[[:space:]]+' /boot/grub/grub.conf root (hd0,0) kernel /vmlinuz-2.6.18-348.el5 ro root=LABEL=/ rhgb quiet initrd /initrd-2.6.18-348.el5.img
11. 顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行。
[root@rhel-5 tuser1]# grep -E '^#[[:space:]]+[^[:space:]]+' /etc/rc.d/rc.sysinit
12. 打印出netstat -tan
命令執行結果中以LISTEN后跟空白字符結尾的行。
[root@rhel-5 tuser1]# netstat -tan | grep 'LISTEN[[:space:]]*$' tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:3938 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:6000 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:1521 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:6012 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:6013 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:734 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN
13. 添加用戶bash、testbash、basher、nologin(此用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息。
[root@rhel-5 tuser1]# useradd bash [root@rhel-5 tuser1]# useradd testbasher [root@rhel-5 tuser1]# useradd basher [root@rhel-5 tuser1]# useradd -s /sbin/nologin nologin [root@rhel-5 tuser1]# grep -E "(^[[:alpha:]]+):.*\1$" /etc/passwd sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt bash:x:502:504::/home/bash:/bin/bash nologin:x:505:507::/home/nologin:/sbin/nologin
原創文章,作者:N21_未來人,如若轉載,請注明出處:http://www.www58058.com/27029
寫的很好,排版也很棒,加油