1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。

1 2 3 4 [root@localhost tuser1]# cp -r /etc/skel/ /home/tuser1 [root@localhost tuser1]# chmod -R go= /home/tuser1/ [root@localhost tuser1]# ll -d /home/tuser1/ drwx------. 2 root root 71 Dec 26 08:40 /home/tuser1/

2、编辑/etc/group文件,添加组hadoop。

1 [root@localhost tuser1]# echo "hadoop:x:2019:" >> /etc/group

3、手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。

1 2 3 4 [root@localhost tuser1]# echo "hadoop:x:2003:2019::/home/hadoop:/bin/bash" >> /etc/passwd [root@localhost tuser1]# tail -2 /etc/passwd slackware:x:2002:2016::/home/slackware:/bin/tcsh hadoop:x:2003:2019::/home/hadoop:/bin/bash

4、复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。

1 2 3 4 [root@localhost tuser1]# cp -r /etc/skel/ /home/hadoop [root@localhost tuser1]# chmod -R go= /home/hadoop/ [root@localhost tuser1]# ll -d /home/hadoop/ drwx------. 2 root root 71 Dec 26 08:42 /home/hadoop/

5、修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。

1 2 3 4 [root@localhost tuser1]# chown -R hadoop:hadoop /home/hadoop/ [root@localhost tuser1]# ll //home/hadoop/ total 0 -rw-------. 1 hadoop hadoop 0 Dec 26 08:42 1

6、显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式。

1 2 3 4 5 6 7 8 [root@localhost tuser1]# cat /proc/meminfo |grep "^[sS]" SwapCached: 0 kB SwapTotal: 9764860 kB SwapFree: 9764860 kB Shmem: 6860 kB Slab: 62908 kB SReclaimable: 23144 kB SUnreclaim: 39764 kB

1 2 3 4 5 6 7 8 [root@localhost tuser1]# cat /proc/meminfo |grep -i "^s" SwapCached: 0 kB SwapTotal: 9764860 kB SwapFree: 9764860 kB Shmem: 6860 kB Slab: 62916 kB SReclaimable: 23144 kB SUnreclaim: 39772 kB

7、显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户。

1 2 [root@localhost /]# cat /etc/passwd|grep -v "/bin/bash$"|cut -d: -f1|wc -l 21

8、显示/etc/passwd文件中其默认shell为/bin/bash的用户。

1 2 3 4 5 6 7 8 [root@localhost /]# cat /etc/passwd|grep "/bin/bash$" |cut -d: -f1 root centos mageia hadoop bash testbash basher

9、找出/etc/passwd文件中的一位数或两位数。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 [root@localhost tuser1]# grep -o "<[[:digit:]]{1,2}>" /etc/passwd 00 1 1 2 2 3 4 4 7 5 06 07 08 12 11 012 14 50 99 99 81 81 89 89 74 74 48 48

10、显示/boot/grub/grub.conf中以至少一个空白字符开头的行。

1 [root@localhost /]# grep "^[[:space:]]+" /boot/grub/gurb.conf

11、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行。

1 [root@localhost /]# cat /etc/rc.d/rc.sysinit |grep "^#[[:space:]]+[^[:space:]]"

12、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行。

1 2 3 4 5 [root@localhost tuser1]# netstat -tan|grep "LISTEN[[:space:]]$" |cat -E 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),而后找出当前系统上其用户名和默认shell相同的用户的信息。

1 2 3 4 5 6 [root@localhost /]# cat /etc/passwd|egrep "^([^:]+>).*\1$" 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:2004:2004::/home/bash:/bin/bash nologin:x:2007:2007::/home/nologin:/sbin/nologin