第四周作业

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

[root@localhost ~]# cp -r /etc/skel/ /home/tuser1
[root@localhost ~]# chmod go= /home/tuser1/ -R
[root@localhost ~]# ll -a /home/tuser1/
total 12
drwx------  3 root root  74 Jun  2 14:27 .
drwxr-xr-x. 8 root root  84 Jun  2 14:27 ..
-rw-------  1 root root  18 Jun  2 14:27 .bash_logout
-rw-------  1 root root 193 Jun  2 14:27 .bash_profile
-rw-------  1 root root 231 Jun  2 14:27 .bashrc
drwx------  4 root root  37 Jun  2 14:27 .mozilla

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

[root@localhost ~]# vim /etc/group
hadoop:x:2019:

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

[root@localhost ~]# vim /etc/passwd
hadoop:x:2019:2019::/home/hadoop:/bin/bash
[root@localhost ~]# id hadoop
uid=2019(hadoop) gid=2019(hadoop) groups=2019(hadoop)

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

[root@localhost ~]# cp -r /etc/skel/ /home/hadoop 
[root@localhost ~]# chmod go= /home/hadoop/ 
[root@localhost ~]# ll -d /home/hadoop/
drwx------ 3 root root 74 Jun  2 14:40 /home/hadoop/

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

[root@localhost ~]# chown hadoop:hadoop /home/hadoop/ -R
[root@localhost ~]# ll -a /home/hadoop/
total 16
drwx------   3 hadoop hadoop   74 Jun  2 14:40 .
drwxr-xr-x. 10 root   root   4096 Jun  2 14:40 ..
-rw-r--r--   1 hadoop hadoop   18 Jun  2 14:40 .bash_logout
-rw-r--r--   1 hadoop hadoop  193 Jun  2 14:40 .bash_profile
-rw-r--r--   1 hadoop hadoop  231 Jun  2 14:40 .bashrc
drwxr-xr-x   4 hadoop hadoop   37 Jun  2 14:40 .mozilla

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

[root@localhost ~]# cat /tmp/meminfo |grep -i "^s"
she is a teacher
SwapCached:         5368 kB
SwapTotal:       2097148 kB
SwapFree:        2079808 kB
Shmem:             17648 kB
Slab:             198104 kB
SReclaimable:     146900 kB
SUnreclaim:        51204 kB

[root@localhost ~]# cat /tmp/meminfo |grep -E  "^(S|s)"
she is a teacher
SwapCached:         5368 kB
SwapTotal:       2097148 kB
SwapFree:        2079808 kB
Shmem:             17648 kB
Slab:             198104 kB
SReclaimable:     146900 kB
SUnreclaim:        51204 kB

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

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

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

[root@localhost ~]# cat /etc/passwd |grep "/bin/bash$" |cut -d: -f1 
root
zach
test
mageia
test1
hadoop

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

[root@localhost ~]# cat /etc/passwd |grep -o -E "\<[0-9]{1,2}\>"

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

[root@localhost ~]# cat /boot/grub2/grub.cfg |grep '^[[:space:]]\+'
  load_env
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
   set default="${saved_entry}"
  menuentry_id_option="--id"
  menuentry_id_option=""
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
    ......
    ......

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

[root@localhost rc.d]# cat /etc/rc.d/rc.local |grep '^#[[:space:]]\+[^[:space:]]\+'
# 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.
# 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@localhost tmp]# netstat -tan |grep -E '(LISTEN$)|(LISTEN[[:space:]]*$)'
tcp        0      0 0.0.0.0:873             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:25151         0.0.0.0:*               LISTEN     
tcp6       0      0 :::873                  :::*                    LISTEN     
tcp6       0      0 :::80                   :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN     
tcp6       0      0 :::443                  :::*                    LISTEN     

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

[root@localhost tmp]# useradd bash
[root@localhost tmp]# useradd testbash
[root@localhost tmp]# useradd basher
[root@localhost tmp]# useradd -s /sbin/nologin nolgin 
[root@localhost tmp]# cat /etc/passwd |grep "^\(\<.*\>\).*\1$"
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:2020:2020::/home/bash:/bin/bash
nologin:x:2023:2023::/home/nolgin:/sbin/nologin

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/100248

(1)
dyzhoudyzhou
上一篇 2018-06-03 19:24
下一篇 2018-06-03 20:35

相关推荐

  • N31第六周作业

    本周(7.23–7.29)第六周 1、简述osi七层模型和TCP/IP五层模型 OSI 七层模型 1、应用层:OSI 参考模型中最靠近用户的一层,为计算机用户提供应用接口,也为用户直接提供各种网络服务。我们常见应用层的网络服务协议有:HTTP,HTTPS,FTP,POP3、SMTP等。 2、表示层:提供各种用于应用层数据的编码和转换功能,确保一个…

    Linux笔记 2018-08-01
  • VMware安装CentOS6系统图文详解

    在VMware上安装CentOS6系统,分两个步骤,根据自己的需求创建虚拟机,然后将CentOS6系统光盘挂载到虚拟机中安装系统。 一:创建虚拟机 点击创建虚拟机   这里我们选择系统推荐的典型模式。   我们这里先不选择安装程序光盘映像文件,随后再安装系统,选择下面一项。 操作系统选择Linux  CentOS 64位的。 由于我们计划…

    2018-03-31
  • Nginx认证模块与状态监测模块使用示例

    Nginx认证模块与状态监测模块使用示例 一、环境准备 1. 软件版本 CentOS7.4 httpd-tools.x86_64        2.4.6-67.el7.centos.6 nginx.x86_64                  1:1.12.2-2.el7 2. 软件安装 nginx的安装需要epel源,没有配置epel可以直接yum安装…

    2018-06-29
  • 加密与安全

    加密与安全 SSH端口转发 SSH 会自动加密和解密所有 SSH 客户端与服务端之间的网络数据。但是,SSH 还能够将其他 TCP 端口的网络数据通过 SSH 链接来转发,并且自动提供了相应的加密及解密服务。这一过程也被叫做“隧道”(tunneling),这是因为 SSH 为其他 TCP 链接提供了一个安全的通道来进行传输而得名。例如,Telnet,SMTP…

    Linux笔记 2018-06-11
  • 第一周

    作业

    Linux笔记 2018-06-21
  • liunx 命令帮助

    — help和-h   选项如下:

    Linux笔记 2018-04-01

评论列表(1条)

  • 马哥教育
    马哥教育 2018-06-07 09:51

    修改权限建议学习一下如何用数字表示。