第4周作业

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

方法1:
[root@192 ]# cp -r /etc/skel/ /home/tuser1
[root@192 \ ]# chmod -R og= /home/tuser1/
[root@192 skel]# ll
   总用量 32
   -rwx------. 1 root root 24681 3月  29 02:28 123
   -rwx------. 1 root root     5 3月  29 02:28 abc
方法2:
[root@192 ]# cp -r /etc/skel/ /home/tuser1
[root@192 skel]# chmod -R 700 /home/tuser1/
[root@192 skel]# ll
   总用量 32
   -rwx------. 1 root root 24681 3月  29 02:28 123
   -rwx------. 1 root root     5 3月  29 02:28 abc

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

[root@192 skel]# vim /etc/group     --手动编辑增加 hadoop:x:2020:
[root@192 skel]# tail -1 /etc/group
               hadoop:x:2020:

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

[root@192 skel]# vim /etc/passwd
[root@192 skel]# tail -1 /etc/passwd
               hadoop:x:102:2020:hadoop:/home/hadoop:/bin/bash

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

[root@192 home]# cp -R /etc/skel/ /home/hadoop
[root@192 home]# chmod -R 700 /home/hadoop/
[root@192 home]# ll /home/hadoop/
               总用量 32
               -rwx------. 1 root root 24681 3月  29 03:16 123
               -rwx------. 1 root root     5 3月  29 03:16 abc

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

[root@192 home]# chown hadoop:hadoop hadoop
[root@192 home]# ll -a
               总用量 3372756
               drwxr-xr-x.  6 root     root           94 3月  29 03:16 .
               dr-xr-xr-x. 19 root     root         4096 3月  29 02:04 ..
               drwx------.  2 deplay01 test01         79 3月  29 02:21 deplay01
               drwx------.  2 hadoop   hadoop         79 3月  29 03:16 hadoop
               -rw-r--r--.  1 root     root   3453696911 1月  14 03:25 linuxx64_12201_database.zip
               drwx------.  2 play01   test02         59 3月  29 02:23 play01
               drwx------.  3 root     root           70 3月  29 02:28 tuser1

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

方法1:    
  [root@192 home]# grep "^[Ss]" /proc/meminfo       --行首锚定
                   SwapCached:            0 kB
                   SwapTotal:       2097148 kB
                   SwapFree:        2097148 kB
                   Shmem:              8844 kB
                   Slab:             145888 kB
                   SReclaimable:      92880 kB
                   SUnreclaim:        53008 kB
方法2:
  [root@192 home]# grep -i "^s" /proc/meminfo         --忽略字符大小写
                   SwapCached:            0 kB
                   SwapTotal:       2097148 kB
                   SwapFree:        2097148 kB
                   Shmem:              8844 kB
                   Slab:             145888 kB
                   SReclaimable:      92880 kB
                   SUnreclaim:        53008 kB
方法3:
  [root@192 home]# egrep '^(s|S)' /proc/meminfo   --扩展正则表达式
                   SwapCached:            0 kB
                   SwapTotal:       2097148 kB
                   SwapFree:        2097148 kB
                   Shmem:              8844 kB
                   Slab:             145920 kB
                   SReclaimable:      92912 kB
                   SUnreclaim:        53008 kB

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

[root@192 home]# 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
               deplay01:x:100:2018::/home/deplay01:/bin/bash
               play01:x:101:2019::/home/play01:/bin/bash
               hadoop:x:102:2020:hadoop:/home/hadoop:/bin/bash

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

[root@192 home]# grep '/bin/bash$' /etc/passwd
1
2
9、找出/etc/passwd文件中的一位数或两位数。

[root@192 home]# grep -o '\<([0-9]{1,2})\>' /etc/passwd
                   3
                   12
                   11

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

[root@192 grub]# grep "^[[:space:]]+" /boot/grub/grub.conf
                sdsdsds
                 ddddd
                  d1323
                ssssss
                fffff
                   SADSAFSAFSAF
                SDSD
                  @#$%
                !e~都是

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

[root@192 rc.d]# grep "^#[[:space:]]+[^[:space:]]" rc.local_bak
               # 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.
               #   333
               # 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命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行。

[root@192 rc.d]# netstat -tan |grep 'LISTEN[[:space:]]+'
               tcp        0      0 0.0.0.0:22              0.0.0.0:               LISTEN    
               tcp6       0      0 :::22                   :::
                   LISTEN  

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

    [root@192 rc.d]# useradd testbash
    [root@192 rc.d]# useradd bash
    [root@192 rc.d]# useradd basher
    [root@192 rc.d]# useradd -s /sbin/nologin nologin
    [root@192 rc.d]# grep "^([^:])+.*\1$" /etc/passwd

猜你喜欢

转载自blog.51cto.com/13717728/2175996