第四周<<复制/etc/skel目录为/home/tuser1。。。>>

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

[root@wujunjie ~]# cp -a /etc/skel/ /home/tuser1
[root@wujunjie ~]# ls -ld /home/tuser1/
drwxr-xr-x. 3 root root 4096 Aug 10 16:23 /home/tuser1/
[root@wujunjie ~]# chmod -R go-rwx /home/tuser1/
[root@wujunjie ~]# ls -al /home/tuser1/
total 24
drwx------. 3 root root 4096 Aug 10 16:23 .
drwxr-xr-x. 7 root root 4096 Sep  7 13:52 ..
-rw-------. 1 root root   18 Aug  3  2016 .bash_logout
-rw-------. 1 root root  193 Aug  3  2016 .bash_profile
-rw-------. 1 root root  231 Aug  3  2016 .bashrc
drwx------. 4 root root 4096 Aug 10 16:22 .mozilla

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

[root@wujunjie ~]# vim /etc/group
[root@wujunjie ~]# tail -1 /etc/group
hadoop:x:2020:

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

[root@wujunjie ~]# tail -1 /etc/passwd
hadoop:x:1111:2020:hadoop:/home/hadoop:/bin/bash

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

[root@wujunjie ~]# cp -a /etc/skel/ /home/hadoop
[root@wujunjie ~]# chmod go-rwx /home/hadoop/
[root@wujunjie ~]# ls -ld /home/hadoop/
drwx------. 3 root root 4096 Aug 10 16:23 /home/hadoop/

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

[root@wujunjie ~]# chown -R hadoop:hadoop /home/hadoop/
[root@wujunjie ~]# ls -la /home/hadoop/
total 24
drwx------. 3 hadoop hadoop 4096 Aug 10 16:23 .
drwxr-xr-x. 8 root   root   4096 Sep  7 14:00 ..
-rw-r--r--. 1 hadoop hadoop   18 Aug  3  2016 .bash_logout
-rw-r--r--. 1 hadoop hadoop  193 Aug  3  2016 .bash_profile
-rw-r--r--. 1 hadoop hadoop  231 Aug  3  2016 .bashrc
drwxr-xr-x. 4 hadoop hadoop 4096 Aug 10 16:22 .mozilla

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

[root@wujunjie ~]# cat /proc/meminfo |grep -i "^s"
SwapCached:          252 kB
SwapTotal:       2047996 kB
SwapFree:        2047300 kB
Shmem:              8176 kB
Slab:              98036 kB
SReclaimable:      48252 kB
SUnreclaim:        49784 kB
[root@wujunjie ~]# egrep "^(s|S)" /proc/meminfo 
SwapCached:          252 kB
SwapTotal:       2047996 kB
SwapFree:        2047300 kB
Shmem:              8176 kB
Slab:              98036 kB
SReclaimable:      48252 kB
SUnreclaim:        49784 kB
[root@wujunjie ~]# grep "^[sS]" /proc/meminfo 
SwapCached:          252 kB
SwapTotal:       2047996 kB
SwapFree:        2047300 kB
Shmem:              8176 kB
Slab:              98036 kB
SReclaimable:      48252 kB

SUnreclaim: 49784 kB

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

[root@wujunjie ~]# grep -v "/sbin/nologin$" /etc/passwd|cut -d: -f1
root
sync
shutdown
halt
wujunjie
mageia
slackware
hadoop

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

[root@wujunjie ~]# grep "/bin/bash$" /etc/passwd|cut -d: -f1
root
wujunjie
mageia
hadoop

九、找出/etc/passwd文件中的一位数或两位数;

[root@wujunjie ~]# egrep -o "\<[[:digit:]]{1,2}\>" /etc/passwd|tr "\n" ","
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,59,59
,32,32,76,29,29,75,75,38,38,42,42,74,74,70,70,89,89,72,72[root@wujunjie ~]#
[root@wujunjie ~]# egrep -o "\<[[:digit:]][[:digit:]]?\>" /etc/passwd|tr "\n" ","
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,59,59
,32,32,76,29,29,75,75,38,38,42,42,74,74,70,70,89,89,72,72[root@wujunjie ~]#

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

[root@wujunjie ~]# grep "^[[:space:]]\+" /boot/grub/grub.conf 
  ddasdasdasdasd
 dsddas das
  asdadadadasda
    asdddddadasdas
  asdaddasdd
 dsdadasdsadasdasd
     dsaddasdasdadasdasdasd

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

[root@wujunjie ~]# grep "^#[[:space:]]\+[^[:space:]]\+" /etc/rc.d/rc.sysinit
#  root:x:0:0:root:/root:/bin/bash
#  daemon:x:2:2:daemon:/sbin:/sbin/nologin
# adm:x:3:4:adm:/var/adm:/sbin/nologin
#    lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
# sync:x:5:0:sync:/sbin:/bin/sync
# shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
#    halt:x:7:0:halt:/sbin:/sbin/halt
#  mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
#   games:x:12:100:games:/usr/games:/sbin/nologin

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

[root@wujunjie ~]# netstat  -tan|grep "LISTEN[[:space:]]\+$"
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN     
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN     
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 :::111                  :::*                    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     

十三、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;

[root@wujunjie ~]# useradd bash
[root@wujunjie ~]# useradd testbash
[root@wujunjie ~]# useradd basher
[root@wujunjie ~]# useradd -s /sbin/nologin nologin
[root@wujunjie ~]# 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:2003:2003::/home/bash:/bin/bash
nologin:x:2006:2006::/home/nologin:/sbin/nologin

你可能感兴趣的:(第四周<<复制/etc/skel目录为/home/tuser1。。。>>)