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

相关推荐

  • SSL应用系列之一:CA证书颁发机构(中心)安装图文详解

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://jeffyyko.blog.51cto.com/28563/140518        如果你需要在组织里发布exchange,或者需要给IIS配置SSL的访问方…

    Linux干货 2015-03-26
  • Bash Shell编程初学基础篇之二

    Bash Shell编程初学基础篇之二    时间如白驹过隙,一晃过去了几周,一切的计划都没有变化快。当你制定计划实施时,在这期间却会发生许多打乱我们计划的事情,但是我们还是要坚持下去,胜利是属于坚持到最后的人!实践出真理,中级基本结束了,需要回过头了好好总结一下了。心中总有好多话想找个同行唠唠;不废话了,估计大家都烦了!总有一天,你会成…

    Linux干货 2015-05-11
  • TCP 的那些事儿(上)

       TCP是一个巨复杂的协议,因为他要解决很多问题,而这些问题又带出了很多子问题和阴暗面。所以学习TCP本身是个比较痛苦的过程,但对于学习的过程却能让人有很多收获。关于TCP这个协议的细节,我还是推荐你去看W.Richard Stevens的《TCP/IP 详解 卷1:协议》(当然,你也可以去读一下RFC793以及后面N多的RFC)。另…

    Linux干货 2015-04-01
  • CentOS系统启动流程、selinux、Systemd剖析

    交互式登录配置文件读取顺序: /etc/profile –> /etc/profile.d/*.sh –> ~/.bash_profile –> ~/.bashrc –> /etc/bashrc 非交互式登录配置文件读取顺序: ~/.bashrc –> /etc/bas…

    Linux干货 2018-03-04
  • LAMP 基于httpd 2.4

    一 安装前准备 说明 操作系统:CentOS 7 64位 Apache 版本:httpd-2.4.6-40.el7.centos.x86_64 httpd服务器ip:192.168.1.4   1.  配置好IP、DNS 、网关,确保使用远程连接工具能够连接服务器 2.     &nbsp…

    Linux干货 2016-04-05
  • LVM 2 介绍以及怎么使用?

    一、 LVM是什么? LVM利用Linux内核的device-mapper来实现存储系统的虚拟化(系统分区独立于底层硬件)。 通过LVM,你可以实现存储空间的抽象化并在上面建立虚拟分区(virtual partitions),可以更简便地扩大和缩小分区,可以增删分区时无需担心某个硬盘上没有足够的连续空间, without getting caught up …

    Linux干货 2017-01-06