Linux权限管理与grep命令应用(第四周)

第四周作业

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

[root@localhost ~]# cp -r /etc/skel/ /home/tuser1
[root@localhost ~]# chmod -R g=,o= /home/tuser1/
[root@localhost ~]# ll -a /home/tuser1/
total 12
drwx------. 2 root root  59 Sep 11 21:06 .
drwxr-xr-x. 7 root root  78 Sep 11 21:06 ..
-rw-------. 1 root root  18 Sep 11 21:06 .bash_logout
-rw-------. 1 root root 193 Sep 11 21:06 .bash_profile
-rw-------. 1 root root 231 Sep 11 21:06 .bashrc

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

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

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

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

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

[root@localhost ~]# cp -r /etc/skel/ /home/hadoop
[root@localhost ~]# chmod g=,o= /home/hadoop/
[root@localhost ~]# ll -d /home/hadoop/
drwx------. 2 root root 59 Sep 11 21:26 /home/hadoop/

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

[root@localhost ~]# chown -R hadoop:hadoop /home/hadoop/
[root@localhost ~]# ll -a /home/hadoop/
total 12
drwx------. 2 hadoop hadoop  59 Sep 11 21:26 .
drwxr-xr-x. 8 root   root    91 Sep 11 21:26 ..
-rw-r--r--. 1 hadoop hadoop  18 Sep 11 21:26 .bash_logout
-rw-r--r--. 1 hadoop hadoop 193 Sep 11 21:26 .bash_profile
-rw-r--r--. 1 hadoop hadoop 231 Sep 11 21:26 .bashrc

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

[root@localhost ~]# grep "^[sS]" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              6824 kB
Slab:              58404 kB
SReclaimable:      22476 kB
SUnreclaim:        35928 kB

[root@localhost ~]# grep -i "^[s]" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              6824 kB
Slab:              58404 kB
SReclaimable:      22476 kB
SUnreclaim:        35928 kB

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

[root@localhost ~]# grep -v "/sbin/nologin$" /etc/passwd | cut -d: -f1

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

[root@localhost ~]# grep "/bin/bash$" /etc/passwd | cut -d: -f1

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

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

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

[root@localhost ~]# grep "^[[:space:]]" /boot/grub/grub.conf

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

[root@localhost ~]# grep "^#[[:space:]]\+[^[:space:]]" /etc/rc.d/rc.sysinit

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

[root@localhost ~]# netstat -tan | grep "LISTEN[[:space:]]\+$"

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

[root@localhost ~]# grep "^\(\<.\+\>\).*\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:3004:3004::/home/bash:/bin/bash
nologin:x:3007:3007::/home/nologin:/sbin/nologin

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

(0)
baronbaron
上一篇 2016-09-15 22:21
下一篇 2016-09-15 22:21

相关推荐

  • linux iptables替代工具nftables

    1 使用 FirewallD 构建动态防火墙 1.1 “守护进程” 1.2 静态防火墙(system-config-firewall/lokkit) 1.3 使用 iptables 和 ip6tables 的静态防火墙规则 1.4 什么是区域? 1.4.1 预定义的服务 1.4.2 端口和…

    Linux干货 2015-03-11
  • 始于此

         “路漫漫其修远兮,吾将上下而求索”,一段路程的结束,意味着一段路程的开始,同岁月般,永远也不能回到出发的那一刻,你所能做的,就是一路走下去。回顾珍惜,却不能逗留。         我的学习宣言是“功崇惟志,业广惟勤”,时刻告诉自己,“功”出…

    Linux干货 2016-11-28
  • Linux Sysadmin–part4

    一、请详细描述CentOS系统的启动流程(详细到每个过程系统做了哪些事情) A.POST加电自检 主板在接通电源后,系统首先由POST程序来对内部各个设备进行检查,自检中如发现有错误,将按两种情况处理:对于严重故障(致命性故障)则停机,此时由于各种初始化操作还没完成,不能给出任何提示或信号;对于非严重故障则给出提示或声音报警信号,等待用户处理。 B.BIOS…

    2017-10-10
  • 新的征程即将开始……

    新的征程,新的开始,开博祭旗篇!!!

    Linux干货 2016-12-26
  • 马哥教育网络班21期第七周作业

    1、创建一个10G分区,并格式为ext4文件系统;   (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;   (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; [root@localhost ~]#…

    Linux干货 2016-10-09
  • 8.16

    for 循环是相对比较简单的循环,任何一个循环里面都可以嵌套循环,用for可以解决简单逻辑上的任何循环 。 有两种基本格式:for i in " ";do         或者dor((i=0;i<=9;i++))可以嵌套if或者while等循环 if循环。最重要的是判断的条件,if意为如果什…

    Linux干货 2016-08-19