权限管理和文本过滤

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

[root@study ~]# cp -r /etc/skel/ /home/tuser1|chmod -R 700 tuser1/
[root@study home]# ll
total 4
drwx------. 4 kang      kang     4096 Nov  1 06:41 kang
drwx------. 2      1100     1100   59 Nov 14 07:40 linux
drwx------. 2 mandriva  distro     59 Nov 14 07:38 mandriva
drwx------. 2 mysql     mysql      59 Nov 14 08:09 mysql
drwx------. 2 openstack clouds     59 Nov 14 08:06 openstack
drwx------. 2 slackware distro     59 Nov 14 07:51 slackware
drwx------. 2 root      root       59 Nov 21 04:36 tuser1
drwx------. 2 xiaokang  xiaokang   79 Nov 14 08:28 xiaokang

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

[root@study home]# vi /etc/group
mysql:x:3004:
hadoop:x:3009
"/etc/group" 48L, 677C written

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

[root@study home]# vi /etc/passwd
mysql:x:3004:3004::/home/mysql:/sbin/nologin
hadoop:x:3009:3009::/home/hadoop:/sbin/nologin
~
"/etc/passwd" 28L, 1367C written
[root@study home]# id hadoop
uid=3009(hadoop) gid=3009(hadoop) groups=3009(hadoop)

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

[root@study home]# cp -r /etc/skel/ /home/hadoop|chmod -R 700 /home/hadoop
[root@study home]# ll
total 4
drwx------. 3 root      root       70 Nov 21 04:55 hadoop

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

[root@study home]# chown -R hadoop:hadoop hadoop/|ll
total 4
drwx------. 3 root      root       70 Nov 21 04:55 hadoop

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

[root@study home]# grep -E "^[s|S]" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              6788 kB
Slab:              52804 kB
SReclaimable:      17856 kB
SUnreclaim:        34948 kB

[root@study home]# grep -i "^s" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              6816 kB
Slab:              52848 kB
SReclaimable:      17824 kB
SUnreclaim:        35024 kB

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

[root@study home]# grep -v "/sbin/nologin" /etc/passwd|cut -d: -f1  
root
sync
shutdown
halt
kang
xiaokang
mandriva
slackware
openstack

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

[root@study home]# grep '/bin/bash' /etc/passwd|cut -d: -f1
root
kang
xiaokang
mandriva
openstack

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

[root@study home]# grep -o "[0-9]\{1,2\}" /etc/passwd

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

grep "^[[:space:]]\+" /boot/grub2/grub.cfg

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

[root@study 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

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

[root@study 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

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

[root@study ~]#  grep "^\([a-z]*\>\).*\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:3010:3010::/home/bash:/bin/bash
nologin:x:3013:3013::/home/nologin:/bin/nologin

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

(0)
N24_小康N24_小康
上一篇 2016-11-20
下一篇 2016-11-21

相关推荐

  • N22-浙江-情歌第一周博客作业

    一、计算机的组成及其功能    计算机有五大组成部分:CPU(控制器和运算器)、内存、输入、输出           CPU:运算、控制、寄存、缓存功能           内存:RAM       &nbsp…

    Linux干货 2016-08-15
  • 马哥教育网络版21班第四周作业

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限 [root@localhost ~]# cp -rf /etc/skel/ /home/tuser1 [root@localhost ~]# chmod&n…

    Linux干货 2016-08-05
  • 20160803普通权限与特殊权限及umask

    权限     任何一个可执行程序文件能不能启动为进程,取决发起者对程序文件是否拥有执行权限.即权限决定用户对文件或者目录的使用范围.在Linux系统中,root的权限是最高的,可操作的权限最大,通常情况下root账号只用于管理系统的重要信息,并不做日常维护工作,所以正确设定用户的权限对系统的安全性尤为重要. 普通权限: 文件目录只针对三类…

    Linux干货 2016-08-04
  • week4

    一,复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没 有任何访问权限; cp -r /etc/skel/ /home/tuser1 chmod -R go= /home/tuser1/ 二,编辑/etc/group文件,添加组hado…

    Linux干货 2016-11-18
  • shell 脚本基础作业

    1、编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小 #!/bin/bash :<<EOF 显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小 EOF Host_name=`hostna…

    Linux干货 2016-08-15