趁著這幾天有時間,先把第四周的作業寫了,好在沒有什么新的知識點考核。
1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。
[root@localhost ~]# cp -r /etc/skel/ /home/tuser1 [root@localhost ~]# chmod 700 -R /home/tuser1/ [root@localhost ~]# ll -a /home/tuser1/ total 16 drwx------ 3 root root 70 Dec 20 10:25 . drwxr-xr-x. 11 root root 4096 Dec 20 10:24 .. -rwx------ 1 root root 18 Dec 20 10:24 .bash_logout -rwx------ 1 root root 193 Dec 20 10:24 .bash_profile -rwx------ 1 root root 231 Dec 20 10:24 .bashrc drwx------ 2 root root 59 Dec 20 10:25 skel
2、編輯/etc/group文件,添加組hadoop。
[root@CentOS-template ~]# echo "hadoop:x:3000:" >> /etc/group [root@CentOS-template ~]# tail -2 /etc/group oprofile:x:16: hadoop:x:3000: [root@CentOS-template ~]#
3、手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop。
[root@CentOS-template ~]# echo "hadoop:x:3000:3000::/home/hadoop:/bin/bash" >> /etc/passwd [root@CentOS-template ~]# tail -2 /etc/passwd oprofile:x:16:16:Special user account to be used by OProfile:/home/oprofile:/sbin/nologin hadoop:x:3000:3000::/home/hadoop:/bin/bash
4、復制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒有任何訪問權限。
[root@CentOS-template ~]# cp -r /etc/skel/ /home/hadoop [root@CentOS-template ~]# chmod 700 -R /home/hadoop [root@CentOS-template ~]# ll -a /home/hadoop total 20 drwx------. 2 root root 4096 Dec 21 08:32 . drwxr-xr-x. 3 root root 4096 Dec 21 08:32 .. -rwx------. 1 root root 18 Dec 21 08:32 .bash_logout -rwx------. 1 root root 176 Dec 21 08:32 .bash_profile -rwx------. 1 root root 124 Dec 21 08:32 .bashrc
5、修改/home/hadoop目錄及其內部所有文件的屬主為hadoop,屬組為hadoop。
[root@CentOS-template ~]# chown -R hadoop:hadoop /home/hadoop [root@CentOS-template ~]# ll -a /home/hadoop/ total 20 drwx------. 2 hadoop hadoop 4096 Dec 21 08:32 . drwxr-xr-x. 3 root root 4096 Dec 21 08:32 .. -rwx------. 1 hadoop hadoop 18 Dec 21 08:32 .bash_logout -rwx------. 1 hadoop hadoop 176 Dec 21 08:32 .bash_profile -rwx------. 1 hadoop hadoop 124 Dec 21 08:32 .bashrc
6、顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用三種方式;
[root@CentOS-template ~]# grep "^[sS].*" /proc/meminfo SwapCached: 0 kB SwapTotal: 524280 kB SwapFree: 524280 kB Shmem: 180 kB Slab: 144396 kB SReclaimable: 89904 kB SUnreclaim: 54492 kB [root@CentOS-template ~]# grep -i "^s.*" /proc/meminfo SwapCached: 0 kB SwapTotal: 524280 kB SwapFree: 524280 kB Shmem: 180 kB Slab: 144396 kB SReclaimable: 89904 kB SUnreclaim: 54492 kB [root@CentOS-template ~]# grep -E "^(s|S).*" /proc/meminfo SwapCached: 0 kB SwapTotal: 524280 kB SwapFree: 524280 kB Shmem: 180 kB Slab: 144404 kB SReclaimable: 89912 kB SUnreclaim: 54492 kB
7、顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶;
[root@CentOS-template ~]# 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 hadoop:x:3000:3000::/home/hadoop:/bin/bash
8、顯示/etc/passwd文件中其默認shell為/bin/bash的用戶;
[root@CentOS-template ~]# grep "/bin/bash$" /etc/passwd root:x:0:0:root:/root:/bin/bash hadoop:x:3000:3000::/home/hadoop:/bin/bash
9、找出/etc/passwd文件中的一位數或兩位數;
[root@CentOS-template ~]# grep "\<[0-9]\{1,2\}\>" /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt ...
10、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;
[root@CentOS-template ~]# grep "^[[:space:]]\+" /boot/grub/grub.conf root (hd0,0) kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=UUID=e63bbabe-a6b9-4c27-899d-c223e8c3afbb rd_NO_LUKS rd_NO_LVM.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-431.el6.x86_64.img
11、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;
[root@CentOS-template ~]# grep "^#[[:space:]]\+[^[:space:]]\+" /etc/rc.d/rc.sysinit # /etc/rc.d/rc.sysinit - run once at boot time # Taken in part from Miquel van Smoorenburg's bcheckrc. # Check SELinux status# Print a text banner. # Only read this once. # Initialize hardware # Set default affinity # Load other user-defined modules # Load modules (for backward compatibility with VARs) # Configure kernel parameters ...
12、打出netstat -tan命令執行結果中以‘LISTEN’,后或跟空白字符結尾的行;
[root@CentOS-template ~]# netstat -tan | grep "LISTEN[[:space:]]*$" tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 :::22 :::* LISTEN
13、添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息;
[root@localhost ~]# useradd bash [root@localhost ~]# useradd testbash [root@localhost ~]# useradd basher [root@localhost ~]# useradd -s /sbin/nologin nologin [root@localhost ~]# grep "^\([[:alnum:]]\+[^:]\>\).*\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:4005:4005::/home/bash:/bin/bash nologin:x:4008:4008::/home/nologin:/sbin/nologin
原創文章,作者:N25-Johnny,如若轉載,請注明出處:http://www.www58058.com/64364
正則表達式很容易將人的水平區分開來,作業中完成的很不錯, 今后的工作學習中也要多加利用,再接再勵。