马哥教育网络21期+第四周作业博客

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总用量 12drwx------. 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/grouphadoop: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/passwdhadoop: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 hadoopdrwx------. 3 hadoop hadoop 74 7月  30 13:45 hadoop
[root@localhost /]# ll -a /home/hadoop总用量 12drwx------. 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] 
Sfile:            0 kBSwapFile:       148 kBShmem:        9721438 kBSHanghaiFile:              80 kBSlab:              6132 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;

显示/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/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltbash:x:1001:1001::/home/bash:/bin/bashnologin:x:1004:1004::/home/nologin:/sbin/nologin

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

(0)
Net21_XUNet21_XU
上一篇 2016-09-05
下一篇 2016-09-05

相关推荐

  • linux权限管理

          今天来讲讲linux里面权限的问题,在linux系统中,有这么几类权限,r,w,x,s,t这么几类权限,系统中为什么要有权限这个东西呢,linux一切皆文件,有些文件不想让某些人看到,那么这个时候就需要设置文件的访问的权限了,文件的拥有者一般都是有权力修改删除文件的,但拥有者以外的人未必就能删除修…

    Linux干货 2016-08-04
  • 第二周-作业

    第二周作业: 题1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。 Linux上常见的文件管理类命令有mkdir、touch、cp、mv、rm、stat。     mkdir:创建新目录         用法:mk…

    Linux干货 2016-12-08
  • 高阶函数&&装饰器

    Edit 高阶函数&&装饰器 高阶函数 first class object 函数在python中是一等公民 函数也是对象,可调用的对象 函数可以作为普通比变量、参数、返回值 高阶函数 数学概念:y = g(f(x)) 在数学和计算机科学中,高阶函数应当是至少满足下面一个条件的函数 接受一个或多个函数作为参数 输出一个函数,return 函数…

    Linux干货 2017-10-24
  • 20160802课堂练习题

    练习: 1、  当用户xiaoming对/testdir 目录无执行权限时,意味着无法做哪些操作? 无法cd进入该目录,但可以ls查看到该目录下的文件,其余的任何操作都执行不了。 2、  当用户xiaoqiang对/testdir 目录无读权限时,意味着无法做哪些操作? 能够进入该目录,不能读取到信息;但如果知道有哪些文件及目录是可以创建…

    Linux干货 2016-08-04
  • httpd配置支持https

    httpd配置支持https 建一台私有CA 配置httpd支持ssl协议以及使用证书 测试基于https访问的相应主机 rpm包安装的httpd https https 超文本传输安全协议(英语:Hypertext Transfer Protocol Secure,缩写:HTTPS,也被称为HTTP over TLS,HTTP over SSL或HTTP …

    Linux干货 2016-12-21
  • linux目录分类和各个目录作用-2016-07-21

    linux目录分类和各个目录作用-2016-07-21 Linux安装以后出现的文件目录的作用:  文件系统的类型  LINUX有四种基本文件系统类型:普通文件、目录文件、连接文件和特殊文件,可用file命令来识别。  普通文件:如文本文件、C语言元代码、SHELL脚本、二进制的可执行文件等,可用cat、less、more、vi…

    Linux干货 2016-08-04

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-07 18:45

    完成的非常好,答案的排版需要注意一下,有些地方需要添加换行符哈,加油!