1、復(fù)制/etc/skel目錄為/home/tuser1悄窃,要求/home/tuser1及其內(nèi)部文件的屬組和其它用戶均沒有任何訪問權(quán)限讥电。
[root@localhost ~]# cp -rv /etc/skel /home/tuser1‘/etc/skel’ -> ‘/home/tuser1’‘/etc/skel/.bash_logout’ -> ‘/home/tuser1/.bash_logout’
‘/etc/skel/.bash_profile’ -> ‘/home/tuser1/.bash_profile’
‘/etc/skel/.bashrc’ -> ‘/home/tuser1/.bashrc’
更改權(quán)限:
[root@localhost ~]# chmod -R go= /home/tuser1
驗證內(nèi)部文件:
[root@localhost tuser1]# ls -la /home/tuser1
total 12
d-wx------. 2 root root 62 Aug 21 01:19 .
drwxr-xr-x. 3 root root 20 Aug 21 01:19 ..
-rw-------. 1 root root 18 Aug 21 01:19 .bash_logout
-rw-------. 1 root root 193 Aug 21 01:19 .bash_profile
-rw-------. 1 root root 231 Aug 21 01:19 .bashrc
驗證目錄:
[root@localhost tuser1]# ls -ld /home/tuser1
d-wx------. 2 root root 62 Aug 21 01:19 /home/tuser1
2、編輯/etc/group文件轧抗,添加組hadoop恩敌。
使用nano或vim或vi編輯,以下是使用的nano:
[root@localhost ~]# nano /etc/group
添加hadoop:x:2018
ctrl+o保存横媚,ctrl+x退出
[root@localhost ~]# grep "hadoop" /etc/group
hadoop:x:2018
此處hadoop的引號不加也可以
3纠炮、手動編輯/etc/passwd文件新增一行月趟,添加用戶hadoop,其基本組ID為hadoop組的id號恢口;其家目錄為/home/hadoop孝宗。
[root@localhost ~]# mkdir /home/hadoop
使用nano或vim或vi編輯,以下是使用的nano:
[root@localhost ~]# nano /etc/passwd
添加hadoop:x:2000:2000::/home/hadoop:/sbin/nologin
ctrl+o保存耕肩,ctrl+x退出
驗證:
[root@localhost ~]# grep "hadoop" /etc/passwdhadoop:x:hadoop:hadoop::/home/hadoop:/sbin/nologin
4因妇、復(fù)制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒有任何訪問權(quán)限猿诸。
[root@localhost ~]# cp -rv /etc/skel /home/hadoop
‘/etc/skel’ -> ‘/home/hadoop/skel’‘/etc/skel/.bash_logout’ -> ‘/home/hadoop/skel/.bash_logout’‘/etc/skel/.bash_profile’ -> ‘/home/hadoop/skel/.bash_profile’‘/etc/skel/.bashrc’ -> ‘/home/hadoop/skel/.bashrc’
更改權(quán)限:
[root@localhost ~]# chmod -R go= /home/hadoop
驗證目錄下的文件:
[root@localhost ~]# ls -la /home/hadoop
total 0
drwx------. 3 root root 18 Aug 21 01:48 .
drwxr-xr-x. 4 root root 34 Aug 21 01:44 ..
drwx------. 2 root root 62 Aug 21 01:48 skel
驗證目錄:
drwx------. 3 root root 18 Aug 21 01:48 /home/hadoop
5婚被、修改/home/hadoop目錄及其內(nèi)部所有文件的屬主為hadoop,屬組為hadoop梳虽。
[root@localhost ~]# chown -R hadoop:hadoop /home/hadoop
驗證目錄下的文件:
[root@localhost ~]# ls -la /home/hadoop
total 0
drwx------. 3 hadoop hadoop 18 Aug 21 01:48 .
drwxr-xr-x. 4 root root 34 Aug 21 01:44 ..
drwx------. 2 hadoop hadoop 62 Aug 21 01:48 skel
驗證目錄:
[root@localhost ~]# ls -ld /home/hadoop
drwx------. 3 hadoop hadoop 18 Aug 21 01:48 /home/hadoop
6址芯、顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用兩種方式窜觉;
第一種方式:
[root@localhost ~]# grep "^[sS]" /proc/meminfo
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 7900 kB
Slab: 63796 kB
SReclaimable: 26668 kB
SUnreclaim: 37128 kB
第二種方式:
[root@localhost ~]# grep -i "^s" /proc/meminfo
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 7900 kB
Slab: 63796 kB
SReclaimable: 26668 kB
SUnreclaim: 37128 kB
第三種方式:
[root@localhost ~]# grep "^[s|S]" /proc/meminfo
取得的結(jié)果是一樣的
7谷炸、顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶;
[root@localhost ~]# 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
8竖螃、顯示/etc/passwd文件中其默認shell為/bin/bash的用戶淑廊;
[root@localhost ~]# grep "/bin/bash" /etc/passwd
root:x:0:0:root:/root:/bin/bash
9、找出/etc/passwd文件中的一位數(shù)或兩位數(shù)特咆;
方法一:
[root@localhost ~]# egrep "\<[0-9]{1,2}\>" /etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologin
方法二:
[root@localhost ~]# grep "\<[0-9]\{1,2\}\>" /etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologin
10、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行录粱;
centos沒有/boot/grub/grub.conf文件,我添加了一個文件及一些內(nèi)容在其中
第一種方法:
[root@localhost ~]# grep "^[[:space:]]\+" /boot/grub/grub.conf
?2312313
?safdfadf
第二種方法:
[root@localhost ~]# grep "^[[:space:]]\{1,\}"/boot/grub/grub.conf
?2312313
?safdfadf
第三種方法:
[root@localhost ~]# egrep "[[:space:]]+" /boot/grub/grub.conf
?2312313
?safdfadf
第四種方法:
[root@localhost ~]# egrep "[[:space:]]{1,}" /boot/grub/grub.conf
?2312313
?safdfadf
11腻格、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符啥繁,而后又有至少一個非空白字符的行菜职;
centos7沒有/etc/rc.d/sysinit文件,替換成 /etc/rc.d/rc.local
第一種方法:
[root@localhost ~]# grep "^#[[:space:]]\{1,\}[^[:space:]]\{1,\}" /etc/rc.d/rc.local
# 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.
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
第二種方法:
[root@localhost ~]# grep "^#[[:space:]]\+[^[:space:]]\+" /etc/rc.d/rc.local
# 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.
# 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命令執(zhí)行結(jié)果中以‘LISTEN’旗闽,后或跟空白字符結(jié)尾的行酬核;
[root@localhost ~]# netstat -tan | grep "LISTEN[[:space:]]*$"
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
13、添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin)适室,而后找出當前系統(tǒng)上其用戶名和默認shell相同的用戶的信息嫡意;
[root@localhost ~]# useradd bash
[root@localhost ~]# useradd testbash
[root@localhost ~]# useradd basher
[root@localhost ~]# useradd -s /sbin/nologin nologin
驗證:
[root@localhost ~]# id bash
uid=2001(bash) gid=2001(bash) groups=2001(bash)
[root@localhost ~]# id testbash
uid=2002(testbash) gid=2002(testbash) groups=2002(testbash)
[root@localhost ~]# id basher
uid=2003(basher) gid=2003(basher) groups=2003(basher)
[root@localhost ~]# tail -1 /etc/passwdnologin:x:2004:2004::/home/nologin:/sbin/nologin
找出用戶名與默認shell相同的用戶:
[root@localhost ~]# grep -E "^([^:]+\>).*\1$" /etc/passwdsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltbash:x:2001:2001::/home/bash:/bin/bashnologin:x:2004:2004::/home/nologin:/sbin/nologin