1、復(fù)制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內(nèi)部文件的屬組和其它用戶均沒(méi)有任何訪問(wèn)權(quán)限肠骆。
>>> ll /etc/skel/ -a
????????drwxr-xr-x.? 2 root root? 62 Apr 26 17:20 .
????????drwxr-xr-x. 89 root root 8192 Sep? 5 17:17 ..
????????rw-r--r--.? 1 root root? 18 Aug? 3? 2017 .bash_logout
????????rw-r--r--.? 1 root root? 193 Aug? 3? 2017 .bash_profile
????????rw-r--r--.? 1 root root? 231 Aug? 3? 2017 .bashrc
>>> cp -r /etc/skel/ /home/tuser1 ; chmod -R go-rwx /home/tuser1
>>> ll /home/tuser1/ -a
????????drwx------.? 2 root root? 62 Sep? 7 17:16 .
????????drwxr-xr-x. 16 root root 208 Sep? 7 17:16 ..
????????-rw-------.? 1 root root? 18 Sep? 7 17:16 .bash_logout
????????-rw-------.? 1 root root 193 Sep? 7 17:16 .bash_profile
????????-rw-------.? 1 root root 231 Sep? 7 17:16 .bashrc
2备籽、編輯/etc/group文件,添加組hadoop琼讽。
>>>tail -1? /etc/group?
????????hadoop:x:4007:
3、手動(dòng)編輯/etc/passwd文件新增一行洪唐,添加用戶hadoop钻蹬,其基本組ID為hadoop組的id號(hào);其家目錄為/home/hadoop凭需。
>>>tail -1 /etc/passwd
????????hadoop:x:4007:4007::/home/hadoop:/bin/bash
4问欠、復(fù)制/etc/skel目錄為/home/hadoop肝匆,要求修改hadoop目錄的屬組和其它用戶沒(méi)有任何訪問(wèn)權(quán)限。
>>> mkdir /home/hadoop ; install /etc/skel/.* -m u=rw,go-rwx /home/hadoop/ &> /dev/null
>>> ll /home/hadoop/ -a
????????drwxr-xr-x.? 2 root root? 62 Sep? 7 17:37 .
? ? ? ? drwxr-xr-x. 18 root root 236 Sep? 7 17:34 ..
????????-rw-------.? 1 root root? 18 Sep? 7 17:37 .bash_logout
????????-rw-------.? 1 root root 193 Sep? 7 17:37 .bash_profile
????????-rw-------.? 1 root root 231 Sep? 7 17:37 .bashrc
>>>mkdir /home/hadoop ;install /etc/skel/.*? -m 600 /home/hadoop &> /dev/null
>>>ll hadoop/ -a
????????drwxr-xr-x.? 2 root root? 62 Sep? 7 17:38 .
????????drwxr-xr-x. 18 root root 236 Sep? 7 17:34 ..
????????-rw-------.? 1 root root? 18 Sep? 7 17:38 .bash_logout
????????-rw-------.? 1 root root 193 Sep? 7 17:38 .bash_profile
????????-rw-------.? 1 root root 231 Sep? 7 17:38 .bashrc
>>> cp -r /etc/skel /home/hadoop;chmod? -R go-rwx /home/hadoop
>>> ll hadoop/ -a
????????drwx------.? 2 root root? 62 Sep? 7 17:41 .
????????drwxr-xr-x. 18 root root 236 Sep? 7 17:41 ..
????????-rw-------.? 1 root root? 18 Sep? 7 17:41 .bash_logout
????????-rw-------.? 1 root root 193 Sep? 7 17:41 .bash_profile
????????-rw-------.? 1 root root 231 Sep? 7 17:41 .bashrc
5顺献、修改/home/hadoop目錄及其內(nèi)部所有文件的屬主為hadoop旗国,屬組為hadoop。
>>> ll -a hadoop/
????????drwx------.? 2 root root? 62 Sep? 7 17:41 .
????????drwxr-xr-x. 18 root root 236 Sep? 7 17:41 ..
????????-rw-------.? 1 root root? 18 Sep? 7 17:41 .bash_logout
????????-rw-------.? 1 root root 193 Sep? 7 17:41 .bash_profile
????????-rw-------.? 1 root root 231 Sep? 7 17:41 .bashrc
>>> chown -R hadoop.hadoop? hadoop
>>> ll -a hadoop/
????????drwx------.? 2 hadoop hadoop? 62 Sep? 7 17:41 .
????????drwxr-xr-x. 18 root? root? 236 Sep? 7 17:41 ..
????????-rw-------.? 1 hadoop hadoop? 18 Sep? 7 17:41 .bash_logout
????????-rw-------.? 1 hadoop hadoop 193 Sep? 7 17:41 .bash_profile
????????-rw-------.? 1 hadoop hadoop 231 Sep? 7 17:41 .bashrc
6注整、顯示/proc/meminfo文件中以大寫或小寫S開(kāi)頭的行能曾;用兩種方式;
>>> grep -E '^[sS]' /proc/meminfo 或??
>>>grep -i 's'? ?/proc/meminfo? 或
>>> grep? '^[sS]'? /proc/meminfo
????????SwapCached:? ? ? ? ? ? 0 kB
????????SwapTotal:? ? ? 8257532 kB
????????肿轨。寿冕。。椒袍。
>>> grep -E? '^(s|S)' /proc/meminfo 或
????????SwapCached:? ? ? ? ? ? 0 kB
????????SwapTotal:? ? ? 8257532 kB
????????驼唱。。驹暑。玫恳。
7、顯示/etc/passwd文件中其默認(rèn)shell為非/sbin/nologin的用戶优俘;
?>>> grep -v '/sbin/nologin$' /etc/passwd | cut -d: -f1
????????root
????????sync
????????shutdown
????????halt
????????appuser
????????.......
????????hadoop
8京办、顯示/etc/passwd文件中其默認(rèn)shell為/bin/bash的用戶;
>>>grep '/bin/bash$' /etc/passwd | cut -d: -f1
????????root
????????appuser
????????zabbix
? ? ? ? .....
????????hadoop
9兼吓、找出/etc/passwd文件中的一位數(shù)或兩位數(shù)臂港;
>>>grep -Eo '\<[0-9]{1,2}\>' /etc/passwd
0
0
1
1
2
2
3
4
4
7
5
0
6
0
7
0
8
12
11
0
12
14
50
99
99
81
81
89
89
74
74
32
32
72
72
38
38
48
48
27
27
10、顯示/etc/grub2.cfg中以至少一個(gè)空白字符開(kāi)頭的行视搏;
>>>grep -E '^[[:space:]]{1,}' /etc/grub2.cfg
11、顯示/etc/rc.d/rc.sysinit文件中以#開(kāi)頭县袱,后面跟至少一個(gè)空白字符浑娜,而后又有至少一個(gè)非空白字符的行;
>>>grep -E '^#[[:space:]]{1,}[^[:space:]]{1,}' /etc/grub2.cfg
12式散、打出netstat -tan命令執(zhí)行結(jié)果中以‘LISTEN’筋遭,后或跟空白字符結(jié)尾的行;
>>> netstat -tan | grep -E "LISTEN[[:space:]]?"
>>>netstat -tan | grep "LISTEN[[:space:]]\?"
13暴拄、添加用戶bash, testbash, basher, nologin (此一個(gè)用戶的shell為/sbin/nologin)漓滔,而后找出當(dāng)前系統(tǒng)上其用戶名和默認(rèn)shell相同的用戶的信息;
>>>grep -E '^([^:]{1,}\>).*\1$' /etc/passwd