1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。
~]# cp -r /etc/skel /home/tuser1
~]# ls -la /home/tuser1
total 20
drwxr-xr-x. 3 root root 87 Oct 17 08:47 .
drwxr-xr-x. 27 root root 4096 Oct 17 08:47 ..
-rw-r–r–. 1 root root 18 Oct 17 08:47 .bash_logout
-rw-r–r–. 1 root root 193 Oct 17 08:47 .bash_profile
-rw-r–r–. 1 root root 231 Oct 17 08:47 .bashrc
drwxr-xr-x. 4 root root 37 Oct 17 08:47 .mozilla
-rw-r–r–. 1 root root 658 Oct 17 08:47 .zshrc
~]# chmod -R g-r,o-r /home/tuser1
~]# ls -la /home/tuser1
total 20
drwx–x–x. 3 root root 87 Oct 17 08:47 .
drwxr-xr-x. 27 root root 4096 Oct 17 08:47 ..
-rw——-. 1 root root 18 Oct 17 08:47 .bash_logout
-rw——-. 1 root root 193 Oct 17 08:47 .bash_profile
-rw——-. 1 root root 231 Oct 17 08:47 .bashrc
drwx–x–x. 4 root root 37 Oct 17 08:47 .mozilla
-rw——-. 1 root root 658 Oct 17 08:47 .zshrc
2、編輯/etc/group文件,添加組hadoop。
vim /etc/group
編輯模式下鍵入G進入文件尾
鍵入o進行下行輸入hadoop:x:3000:
esc進入編輯模式
ZZ保存并退出
3、手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop。
vim /etc/passwd
hadoop:x:3000:3000::/home/hadoop:/bin/bash
~]# id hadoop
uid=3000(hadoop) gid=3000(hadoop) groups=3000(hadoop)
4、復制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒有任何訪問權限。
~]# cp -r /etc/skel /home/hadoop
~]# ls -la /home/hadoop
total 20
drwxr-xr-x. 3 root root 87 Oct 17 09:07 .
drwxr-xr-x. 27 root root 4096 Oct 17 09:07 ..
-rw-r–r–. 1 root root 18 Oct 17 09:07 .bash_logout
-rw-r–r–. 1 root root 193 Oct 17 09:07 .bash_profile
-rw-r–r–. 1 root root 231 Oct 17 09:07 .bashrc
drwxr-xr-x. 4 root root 37 Oct 17 09:07 .mozilla
-rw-r–r–. 1 root root 658 Oct 17 09:07 .zshrc
~]# chmod -R g-r,o-r /home/hadoop
~]# ls -la /home/hadoop
total 20
drwx–x–x. 3 root root 87 Oct 17 09:07 .
drwxr-xr-x. 27 root root 4096 Oct 17 09:07 ..
-rw——-. 1 root root 18 Oct 17 09:07 .bash_logout
-rw——-. 1 root root 193 Oct 17 09:07 .bash_profile
-rw——-. 1 root root 231 Oct 17 09:07 .bashrc
drwx–x–x. 4 root root 37 Oct 17 09:07 .mozilla
-rw——-. 1 root root 658 Oct 17 09:07 .zshrc
5、修改/home/hadoop目錄及其內部所有文件的屬主為hadoop,屬組為hadoop。
~]# chown -R hadoop.hadoop /home/hadoop
~]# ls -la /home/hadoop
total 20
drwx–x–x. 3 hadoop hadoop 87 Oct 17 09:07 .
drwxr-xr-x. 27 root root 4096 Oct 17 09:07 ..
-rw——-. 1 hadoop hadoop 18 Oct 17 09:07 .bash_logout
-rw——-. 1 hadoop hadoop 193 Oct 17 09:07 .bash_profile
-rw——-. 1 hadoop hadoop 231 Oct 17 09:07 .bashrc
drwx–x–x. 4 hadoop hadoop 37 Oct 17 09:07 .mozilla
-rw——-. 1 hadoop hadoop 658 Oct 17 09:07 .zshrc
6、顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用兩種方式;
~]# cat /proc/meminfo | grep "^[sS]"
SwapCached:0 kB
SwapTotal: 2097148 kB
SwapFree:2097148 kB
Shmem: 9292 kB
Slab: 82384 kB
SReclaimable: 31540 kB
SUnreclaim:50844 kB
~]# cat /proc/meminfo | grep -i "^s"
SwapCached:0 kB
SwapTotal: 2097148 kB
SwapFree:2097148 kB
Shmem: 9292 kB
Slab: 82392 kB
SReclaimable: 31540 kB
SUnreclaim:50852 kB
7、顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶;
~]# cat /etc/passwd | grep -v "/sbin\/nologin$" | cut -d: -f1
root
sync
…
8、顯示/etc/passwd文件中其默認shell為/bin/bash的用戶;
~]# cat /etc/passwd | grep "\/bin\/bash$" | cut -d: -f1
root
void
archlinux
…
9、找出/etc/passwd文件中的一位數或兩位數;
~]# cat /etc/passwd | grep "\<[0-9]\>\|\<[0-9][0-9]\>"
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
…
~]# cat /etc/passwd | grep "\<[0-9]\{1,2\}\>"
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
…
10、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;
~]# cat /boot/grub/grub.conf | grep "^[[:space:]]\+"
root (hd0,0)
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUK
S rd_NO_MD rd_LVM_LV=VolGroup/lv_swap crashkernel=auto.UTF-8 rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quietinitrd /initramfs-2.6.32-431.el6.x86_64.img
11、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;
~]# cat /etc/rc.d/rc.sysinit | grep "^#[[:space:]]\+\.*[^[:space:]]\+"
# /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.
…
12、打出netstat -tan命令執行結果中以‘LISTEN’,后或跟空白字符結尾的行;
~]# netstat -tan | grep "LISTEN[[:space:]]*$"
tcp0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp0 0 127.0.0.1:250.0.0.0:* LISTEN
tcp0 0 127.0.0.1:6010 0.0.0.0:* LISTEN
tcp0 0 0.0.0.0:59740 0.0.0.0:* LISTEN
tcp0 0 :::111 :::*LISTEN
tcp0 0 :::22 :::*LISTEN
tcp0 0 ::1:631 :::*LISTEN
tcp0 0 ::1:25 :::*LISTEN
tcp0 0 ::1:6010:::*LISTEN
tcp0 0 :::42689:::*LISTEN
13、添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息;
~]# useradd bash
~]# useradd testbash
~]# useradd basher
~]# useradd nologin
~]# usermod -s /sbin/nologin nologin
~]#grep -E "(^([^:]+)\>).*\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:500:500::/home/bash:/bin/bash
nologin:x:503:503::/home/nologin:/sbin/nologin
~]# grep "\(^\([^:]\+\)\>\).*\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:500:500::/home/bash:/bin/bash
nologin:x:503:503::/home/nologin:/sbin/nologin
原創文章,作者:N23-蘇州-void,如若轉載,請注明出處:http://www.www58058.com/52342
完成的很好,學有余力的話,可以把一些題目換個正則表達式來完成,加油。