1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。
[root@localhost ~]# cp -r /etc/skel /home/tuser1 [root@localhost ~]# ls -ld /home/tuser1 drwxr-xr-x 3 root root 74 Dec 27 10:23 /home/tuser1 [root@localhost ~]# chmod -R g-r,o-r /home/tuser1 [root@localhost ~]# ls -al /home/tuser1 total 16 d-wx--x--x 3 root root 74 Dec 27 10:23 . drwxr-xr-x. 20 root root 4096 Dec 27 10:23 .. -rw------- 1 root root 18 Dec 27 10:23 .bash_logout -rw------- 1 root root 193 Dec 27 10:23 .bash_profile -rw------- 1 root root 231 Dec 27 10:23 .bashrc drwx--x--x 4 root root 37 Dec 27 10:23 .mozilla
2、编辑/etc/group文件,添加组hadoop。
[root@localhost ~]# vim /etc/group [root@localhost ~]# tail -1 /etc/group hadoop:x:5006
3、手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
[root@localhost ~]# vim /etc/passwd [root@localhost ~]# tail -1 /etc/passwd hadoop:x:3004:5006:/home/hadoop:/bin/bash
4、复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。
[root@localhost ~]# cp -r /etc/skel /home/hadoop [root@localhost ~]# chmod -R g-r,o-r /home/hadoop [root@localhost ~]# ls -al /home/tuser1 total 16 d-wx--x--x 3 root root 74 Dec 27 10:23 . drwxr-xr-x. 21 root root 4096 Dec 28 10:09 .. -rw------- 1 root root 18 Dec 27 10:23 .bash_logout -rw------- 1 root root 193 Dec 27 10:23 .bash_profile -rw------- 1 root root 231 Dec 27 10:23 .bashrc drwx--x--x 4 root root 37 Dec 27 10:23 .mozilla
5、修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
[root@localhost ~]# chown -R hadoop:hadoop /home/hadoop [root@localhost ~]# ls -al /home/hadoop total 16 drwx--x--x 3 hadoop hadoop 74 Dec 28 10:09 . drwxr-xr-x. 21 root root 4096 Dec 28 10:09 .. -rw------- 1 hadoop hadoop 18 Dec 28 10:09 .bash_logout -rw------- 1 hadoop hadoop 193 Dec 28 10:09 .bash_profile -rw------- 1 hadoop hadoop 231 Dec 28 10:09 .bashrc drwx--x--x 4 hadoop hadoop 37 Dec 28 10:09 .mozilla
6、显示/proc/meminfo文件中以大写或小写S开头的行;用三种方式;
[root@localhost ~]# grep -E "^(s|S)" /proc/meminfo SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 13568 kB Slab: 268852 kB SReclaimable: 218164 kB SUnreclaim: 50688 kB
or
[root@localhost ~]# grep -i "^s" /proc/meminfo SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 13568 kB Slab: 268852 kB SReclaimable: 218164 kB SUnreclaim: 50688 kB
or
[root@localhost ~]# grep "^[sS]" /proc/meminfo SwapCached: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Shmem: 13568 kB Slab: 268852 kB SReclaimable: 218164 kB SUnreclaim: 50688 kB
7、显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;
[root@localhost ~]# grep "/sbin/nologin$" /etc/passwd | cut -d: -f1
8、显示/etc/passwd文件中其默认shell为/bin/bash的用户;
[root@localhost ~]# grep "/bin/bash$" /etc/passwd | cut -d: -f1
9、找出/etc/passwd文件中的一位数或两位数;
[root@localhost ~]# grep "\<[0-9]\{1,2\}\>" /etc/passwd
10、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
[root@localhost ~]# grep "^[[:space:]]\+" /boot/grub/grub.conf
11、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
[root@localhost ~]# grep "^#[[:space:]]\+[^[:space:]]\+" /etc/rc.d/rc.sysinit
12、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;
[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:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:631 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN tcp6 0 0 ::1:6010 :::* LISTEN tcp6 0 0 ::1:6011 :::* LISTEN
13、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;
[root@localhost ~]# 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:1015:1015::/home/bash:/bin/bash nologin:x:1018:1018::/home/nologin:/sbin/nologin
原创文章,作者:Powercat,如若转载,请注明出处:http://www.178linux.com/65703