马哥教育网络班21期+第4周作业

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

[root@localhost ~]# cp -r /etc/skel /home/ && mv /home/skel /home/tuser1
[root@localhost ~]# chmod -R g-rwx,o-rwx  /home/tuser1
[root@localhost tuser1]# ll -a
总用量 12
drwx------. 3 root root  74 7月  30 13:31 .
drwx--x--x. 3 root root  43 7月  30 13:31 ..
-rw-------. 1 root root  18 7月  30 13:31 .bash_logout
-rw-------. 1 root root 193 7月  30 13:31 .bash_profile
-rw-------. 1 root root 231 7月  30 13:31 .bashrc
drwx------. 4 root root  37 7月  30 13:31 .mozilla

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

[root@localhost /]# echo "hadoop:x:1000:" >> /etc/group
[root@localhost /]# tail -1 /etc/group
hadoop:x:1000:

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

[root@localhost /]# echo "hadoop:x:1000:1000:hadoop:/home/hadoop:/bin/bash" >> /etc/passwd
[root@localhost /]# tail -1 /etc/passwd
hadoop:x:1000:1000::/home/hadoop:/bin/bash

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

[root@localhost /]# cp -r /etc/skel/ /home && mv /home/skel /home/hadoop
[root@localhost /]# chmod g-rwx,o-rwx /home/hadoop/
[root@localhost /]# ll -a /home | grep hadoop
drwx------.  4 root root    85 7月  30 13:42 hadoop

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

[root@localhost /]# chown -R hadoop:hadoop /home/hadoop
[root@localhost /]# ll /home | grep hadoop
drwx------. 3 hadoop hadoop 74 7月  30 13:45 hadoop
[root@localhost /]# ll -a /home/hadoop
总用量 12
drwx------. 4 hadoop hadoop  85 7月  30 13:42 .
drwx--x--x. 4 root   root    56 7月  30 13:42 ..
-rw-r--r--. 1 hadoop hadoop  18 7月  30 13:42 .bash_logout
-rw-r--r--. 1 hadoop hadoop 193 7月  30 13:42 .bash_profile
-rw-r--r--. 1 hadoop hadoop 231 7月  30 13:42 .bashrc
drwxr-xr-x. 4 hadoop hadoop  37 7月  30 13:42 .mozilla

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

[root@localhost /]# cat /proc/meminfo | grep ^[s,S] 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              8800 kB
Slab:              66536 kB
SReclaimable:      23132 kB
SUnreclaim:        43404 kB
[root@localhost /]# cat /proc/meminfo | grep -i ^s 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              8800 kB
Slab:              66564 kB
SReclaimable:      23156 kB
SUnreclaim:        43408 kB

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

[root@localhost /]# cat /etc/passwd | grep -v /sbin/nologin | awk -F: '{ print $1 }' 
root
sync
shutdown
halt
hadoop

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

[root@localhost /]# cat /etc/passwd | grep  /bin/bash | awk -F: '{ print $1 }'                
root
hadoop

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

[root@localhost /]# grep -o "[0-9]\{1,2\}" /etc/passwd  
0
中间略...
00

10、显示/boot/grub/grub.conf中以至少一个空白字符开头的行(系统为CentOS 7,以/boot/grub2/grub.cfg代替)

[root@localhost grub2]# grep "^[[:space:]]\+" grub.cfg 
  load_env
   set default="${next_entry}"
中间略... 
        initrd16 /initramfs-0-rescue-37e800fd7ca2447eade3a5cb36080c40.img
  source ${config_directory}/custom.cfg
  source $prefix/custom.cfg;

11、显示/etc/rc.d/rc.sysinit文件 中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行(系统为CentOS 7,以/boot/grub2/grub.cfg代替)

[root@localhost /]# cat /boot/grub2/grub.cfg  | grep "^#[[:space:]]\{1,\}[^[:space:]]"
# DO NOT EDIT THIS FILE
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

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

[root@localhost /]# netstat -tan | grep 'LISTEN[[:space:]]'
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: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相同的用户的信息

[root@localhost /]# useradd bash && useradd testbash && useradd basher && useradd -s /sbin/nologin nologin
[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:1001:1001::/home/bash:/bin/bash
nologin:x:1004:1004::/home/nologin:/sbin/nologin

原创文章,作者:lichenhan,如若转载,请注明出处:http://www.178linux.com/26891

(0)
上一篇 2016-08-02 10:55
下一篇 2016-08-02 10:55

相关推荐

  • shell脚本之条件测试

    组合条件测试:在多个条件间实现逻辑运算     与:[ condition1 -a condition2 ]、condition1 && condition2     或:[ condition…

    Linux干货 2015-08-24
  • 关于绑定与不绑定CPU的对比

        此文严格意义上说,我没有很大的把握,其中关于CPU调度域的概念现在还有些混淆,但还是发出来,希望能做点铺路的贡献吧。    另外CPU调度域的原理我没办法自己写,能力尚浅, 只能将IBM知识库 和 另一位博主的文章摘录如下,并添加了些帮助理解的图片,希望能帮助到初学者。 …

    Linux干货 2016-05-03
  • 硬链接与软链接的区别

    硬链接(Hard Link):   硬连接指通过索引节点来进行链接(即一个指针指向文件索引节点)。在Linux的文件系统中,保存在磁盘分区中的文件不管是什么类型都给它分配一个编号,称为索引节点号(Inode Index)。在Linux中,多个文件名指向同一索引节点是存在的。一般这种链接就是硬链接。硬链接的作用是允许一个文件拥有多个有效路径…

    Linux干货 2016-10-20
  • Linux进程管理

    内核的功能:     进程管理 文件系统 网络功能 内存管理 驱动程序 安全功能等     rocess:运行中的程序的一个副本,是被载入内存的一个指令集合      进程ID(Process ID,PID)号码被用来标记各个进程 UID,GID,和…

    Linux干货 2016-09-12
  • 文件处理工具系列(二):行编辑器sed

    1、sed介绍     sed(Stream EDitor),是一种行编辑工具,它一次处理一行内容。处理时,把当前匹配到的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令对这些数据做出相应的增删改查操作,处理完成后,默认输出至屏幕,而未被匹配到的行也将默认输出至屏幕。而原来的文件内容并没有发生改变,除…

    Linux干货 2016-08-11
  • Linux基础知识(六)

    本问主要讲述Linux的基础知识,具体包一下内容: 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; cp /etc/rc.d/rc.sysinit /tmp sed "s/^[[:space:]]\?/#/g" /tmp/rc.sysini…

    Linux干货 2016-10-30

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-02 11:58

    写的很好,排版也很棒,加油