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
下一篇 2016-09-15

相关推荐

  • RAID磁盘冗余探究

    RAID磁盘冗余探究 RAID的全称是Redundant Arrays of Inexpensive Disk,可以翻译为廉价的磁盘冗余阵列。由加利福尼亚大学伯克利分校的一位教授在1988年提出,是一种磁盘管理方式。其产生的初衷是为了降低成本,但是为了达到RAID的功能,其造价并不便宜,所以后来改为Redundant Arrays of Independen…

    2017-08-26
  • 文本处理工具补充之sed命令

    sed:stream editor,行编辑器         sed命令工作原理:它在处理数据时,每次只处理一行,首先把当前处理的行存储在临时缓冲区中,我们称这个缓冲区称为“”模式空间“,接着用sed命令处理缓冲区中的内容,处理完后,把缓冲区中的内容送到屏幕上显示出来,接着去处理…

    Linux干货 2016-08-11
  • LVS-nat-dr

    主程序:ipvsadm 配置文件: 规则保存工具:/usr/sbin/ipvsadm-save 规则重载工具:/usr/sbin/ipvsadm-restore 配置文件:/etc/sysconfig/ipvsadm-config ipvsadm使用: 增:      示例:ipvsadm -A -t 172.16.42.1:8…

    2017-08-08
  • 文件压缩,解压缩及归档

        在Linux的环境中,压缩文件的扩展名大多是:“*.tar, *.tar.gz, *.gz, *.Z, *.bz2, *.xz”,因为 Linux 支持的压缩指令非常多,且不同的指令所用的压缩技术并不相同,当然彼此之间可能就无法互通压缩/解压缩文件,当你下载到某个压缩文件时,自然就需要知道该文件是由哪种压缩指令…

    Linux干货 2016-08-18
  • 3、文本处理命令、用户与组命令练习

    1.列出当前系统上所有已登录用户的用户名,同一个用户登录,则只显示一次 [root@localhost ~]# who root     tty1         2016-08-23 06…

    Linux干货 2016-09-19
  • Shell 位置参数总结

    描述: 位置参数指的是shell脚本的命令行参数,同时也表示shell函数的额函数参数。 说明: 示例: #!/bin/sh echo "number:$#"     # 传给脚本的参数个数 echo "scname:$0" &n…

    Linux干货 2016-08-16