N26-第四周

1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限。
[root@localhost home]# cp -R /etc/skel/ /home/tuser1 && chmod -R g=,o= /home/tuser1 
[root@localhost home]# ll -d /home/tuser1/
drwx——. 2 root root 59 3月   7 20:30 /home/tuser1/
[root@localhost tuser1]# ll -a
总用量 16
drwx——.  2 root root   59 3月   7 20:30 .
drwxr-xr-x. 15 root root 4096 3月   7 20:30 ..
-rw——-.  1 root root   18 3月   7 20:30 .bash_logout
-rw——-.  1 root root  193 3月   7 20:30 .bash_profile
-rw——-.  1 root root  231 3月   7 20:30 .bashrc

2、编辑/etc/group文件,添加组hadoop。
[root@localhost tuser1]# echo ‘hadoop:x:5005:’ >> /etc/group
[root@localhost tuser1]# tail -2 /etc/group
admins:x:5004:slackware
hadoop:x:5005:

3、手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号,其家目录为/home/hadoop。
[root@localhost tuser1]# vim /etc/passwd
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016::/home/slackware:/bin/tcsh
hadoop:x:5005:5005::/home/hadoop:/bin/bash
[root@localhost tuser1]# tail -1 /etc/passwd
hadoop:x:5005:5005::/home/hadoop:/bin/bash

4、复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其他用户没有任何访问权限。
[root@localhost tuser1]# cp -R /etc/skel/ /home/hadoop && chmod g=,o= /home/hadoop
[root@localhost tuser1]# ll -d /home/hadoop/
drwx——. 2 root root 59 3月   7 20:51 /home/hadoop/

5、修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
[root@localhost tuser1]# cd ..
[root@localhost home]# chown -R hadoop:hadoop /home/hadoop/
[root@localhost home]# ll -d /home/hadoop/
drwx——. 2 hadoop hadoop 59 3月   7 20:51 /home/hadoop/

6、显示/proc/meminfo文件中以大写或小写S开头的行,用两种方式。
[root@localhost home]# grep  ‘^[sS]’ /proc/meminfo   
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              6868 kB
Slab:              56628 kB
SReclaimable:      21584 kB
SUnreclaim:        35044 kB  
[root@localhost home]# grep -v ‘^[^sS]’ /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              6868 kB
Slab:              56644 kB
SReclaimable:      21584 kB
SUnreclaim:        35060 kB
7、显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户。
[root@localhost 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
gentoo:x:4001:5002::/var/tmp/gentoo:/bin/bash
fedora:x:4002:4002:Fedora Core:/home/fedora:/bin/tcsh
abc:x:4003:4003::/home/abc:/bin/bash
centos:x:4004:4004::/home/centos:/bin/bash
user1:x:4005:4005::/home/user1:/bin/bash
bash:x:4006:4006::/home/bash:/bin/bash
testbash:x:4007:4007::/home/testbash:/bin/bash
basher:x:4008:4008::/home/basher:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016::/home/slackware:/bin/tcsh
hadoop:x:5005:5005::/home/hadoop:/bin/bash

8、显示/etc/passwd文件中其默认shell为/bin/bash的用户。
[root@localhost home]# grep ‘/bin/bash$’ /etc/passwd
root:x:0:0:root:/root:/bin/bash
gentoo:x:4001:5002::/var/tmp/gentoo:/bin/bash
abc:x:4003:4003::/home/abc:/bin/bash
centos:x:4004:4004::/home/centos:/bin/bash
user1:x:4005:4005::/home/user1:/bin/bash
bash:x:4006:4006::/home/bash:/bin/bash
testbash:x:4007:4007::/home/testbash:/bin/bash
basher:x:4008:4008::/home/basher:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
hadoop:x:5005:5005::/home/hadoop:/bin/bash

9、找出/etc/passwd文件中的一位或两位数。
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
[root@localhost home]# grep ‘\<[[:digit:]]{1,2}\>’ /etc/passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
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

10、显示/boot/grub/grub.conf中以至少一个空白字符开头的行。
[root@localhost home]# grep ‘^[[:space:]]+’ /boot/grub2/grub.cfg 
 load_env
  set default=”${next_entry}”
  set next_entry=
  save_env next_entry
  set boot_once=true
  set default=”${saved_entry}”

11、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行。
[root@localhost home]# grep ‘^#[[:space:]]+.*[^[:space:]]+’ /etc/rc.d/rc.local 

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 home]# netstat -tan | grep ‘LISTEN[[:space:]]\>’ 
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 home]# 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:4006:4006::/home/bash:/bin/bash
nologin:x:4009:4009::/home/nologin:/sbin/nologin

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

(0)
徐 琦徐 琦
上一篇 2017-03-07 17:00
下一篇 2017-03-08 10:44

相关推荐

  • 第十周

    1、请详细描述CentOS系统的启动流程(详细到每个过程系统做了哪些事情) 1.POST 开机加电自检,对计算机的cpu,硬盘,内存等进行检测。 2.BIOS 对引导程序进行探测,并把控制权交给引导程序。 3.MBR Master bootloader record主引导程序.通常位于硬盘第一扇区/dev/hda(0,0)或/dev/sda(0,0). 此阶…

    Linux干货 2017-03-30
  • lnmp部署实验

    Lnmp部署 实验环境: 1、Centos 7主机一台,客户机一台。 2、在centos 7主机上部署:    Nginx  php-fpm  php-mysql  mariadb-server 实验步骤: 1、启动nginx服务,确保80端口打开,启动mariadb-server,确保3306端口…

    Linux干货 2016-10-30
  • 进程和优先级

         什么是进程?我们先来了解一下进程的概念:我们知道操作系统最核心的概念就是进程。进程简单来说就是在操作系统中运行的程序,它是操作系统资源管理的最小单位。但是进程是一个动态的实体,它是程序的一次执行过程。进程和程序的区别在于:进程是动态的,程序是静态的,进程是运行中的程序,而程序是一些保存在硬盘上的可执行代码。    当多个任务要执行时怎么办呢?先执行…

    2017-09-09
  • shell脚本编程之函数

      在编写脚本时经常会遇到某个任务需要重复使用的问题,需每次都要输入同样的代码是件挺烦人的事情,还好可以通过编写函数还简化这项工作。   函数其实就是给一段代码起个名字,在每次使用这段代码的时候可以直接使用函数名来调用就可以了。 一、创建函数   创建函数的格式有两种:   格式1:function 函数名{ &nbs…

    Linux干货 2016-01-05
  • PHP5.4最新特性

    原文Oracle:LAMP 体系有了新的竞争,但此版本中的特性使 PHP 再次挑战极限。 稍微做了修改。: 概述总结:1. 内存和性能改进:大型 PHP 应用程序中可节省 20-50% 的内存。通过各种优化使性能提高 10-30%2. 支持特性Trait3. 精简数组语法,可以定义短数组4. 函数数组解除引用,支持Array dereferenci…

    Linux干货 2015-11-18
  • 关于文件权限管理了解和使用

                    文件权限管理   文件属性格式              文件属性操作 chown          设置文件的所有者…

    系统运维 2016-08-05

评论列表(1条)

  • 马哥教育
    马哥教育 2017-03-14 09:11

    功能上基本实现了,能注意下排版会更好点~加油!