第四周作业

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

[root@unclez ~]# cp -r /etc/skel /home/tuser1
[root@unclez ~]# chmod -R go= /home/tuser1

[root@unclez ~]# ls -al /home/tuser1/
总用量 12
drwx------. 3 root root  74 12月 24 11:00 .
drwxr-xr-x. 5 root root  40 12月 24 11:00 ..
-rw-------. 1 root root  18 12月 24 11:00 .bash_logout
-rw-------. 1 root root 193 12月 24 11:00 .bash_profile
-rw-------. 1 root root 231 12月 24 11:00 .bashrc
drwx------. 4 root root  37 12月 24 11:00 .mozilla

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

[root@unclez ~]# echo "hadoop:x:1001" >> /etc/group
[root@unclez ~]# cat /etc/group | tail -1
hadoop:x:1001

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

[root@unclez ~]# echo "hadoop:x:1001:1001::/home/hadoop:/sbin/nologin" >> /etc/passwd
[root@unclez ~]# cat /etc/passwd | tail -1
hadoop:x:1001:1001::/home/hadoop:/sbin/nologin

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

[root@unclez ~]# cp -r /etc/skel /home/hadoop
[root@unclez ~]# chmod go= /home/hadoop/
[root@unclez ~]# ls -ld /home/hadoop/
drwx------. 3 root root 74 12月 24 11:21 /home/hadoop/

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

[root@unclez ~]# chown -R hadoop.hadoop /home/hadoop/
[root@unclez ~]# ls -al /home/hadoop/
总用量 12
drwx------. 3 hadoop hadoop  74 12月 24 11:21 .
drwxr-xr-x. 6 root   root    53 12月 24 11:21 ..
-rw-r--r--. 1 hadoop hadoop  18 12月 24 11:21 .bash_logout
-rw-r--r--. 1 hadoop hadoop 193 12月 24 11:21 .bash_profile
-rw-r--r--. 1 hadoop hadoop 231 12月 24 11:21 .bashrc
drwxr-xr-x. 4 hadoop hadoop  37 12月 24 11:21 .mozilla

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

[root@unclez ~]# grep -i "^s.*" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       8257532 kB
SwapFree:        8257532 kB
Shmem:             19476 kB
Slab:             131768 kB
SReclaimable:      68284 kB
SUnreclaim:        63484 kB
[root@unclez ~]# grep "^[sS].*" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       8257532 kB
SwapFree:        8257532 kB
Shmem:             19476 kB
Slab:             131768 kB
SReclaimable:      68284 kB
SUnreclaim:        63484 kB
[root@unclez ~]# grep -E "^(s|S).*" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       8257532 kB
SwapFree:        8257532 kB
Shmem:             19476 kB
Slab:             131752 kB
SReclaimable:      68284 kB
SUnreclaim:        63468 kB

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

[root@unclez ~]# grep -v "/sbin/nologin$" /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
amandabackup
zwp

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

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

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

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

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

[root@unclez ~]# grep -E "^[[:space:]]+" /boot/grub/grub.conf

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

[root@unclez ~]# grep -E "^#[[:space:]]+[^[:space:]]+" /etc/rc.d/rc.sysinit

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

[root@unclez ~]# netstat -tan | grep -E "LISTEN[[:space:]]*$"
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           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:631                 :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN

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

[root@unclez ~]# useradd bash
[root@unclez ~]# useradd testbash
[root@unclez ~]# useradd basher
[root@unclez ~]# useradd -s /sbin/nologin nologin
[root@unclez ~]# cat /etc/passwd | tail -4
bash:x:1002:1002::/home/bash:/bin/bash
testbash:x:1003:1003::/home/testbash:/bin/bash
basher:x:1004:1004::/home/basher:/bin/bash
nologin:x:1005:1005::/home/nologin:/sbin/nologin

[root@unclez ~]# 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:1002:1002::/home/bash:/bin/bash
nologin:x:1005:1005::/home/nologin:/sbin/nologin

原创文章,作者:N25-赵叔,如若转载,请注明出处:http://www.178linux.com/64610

赞 (0)
N25-赵叔N25-赵叔
上一篇 2016-12-24 13:21
下一篇 2016-12-24 16:34

相关推荐

  • 电子眼find

     1、摩根定律。         话不多说,先上图。          如图:A和B交集为3    A = 4 + 3  &nbs…

    Linux干货 2016-08-16
  • 内核编译流程和自动化安装

    内核编译         在特定的情况我们机器上面有些硬件特性需要利用起来,但是我们现成的这个内核没有开启这个功能,那就需要重新编译,把这个功能模块加进来,或者打到vmlinux中的核心文件里面。比如ntfs功能,默认系统没有启用此功能,但是系统是带这个功能的,编译的时候时候可以…

    Linux干货 2016-09-18
  • PHP5.4的变化关注—What has changed in PHP 5.4.x

    What has changed in PHP 5.4.x Most improvements in PHP 5.4.x have no impact on existing code. There are a few incompatibilities and new features that should be …

    Linux干货 2015-06-17
  • Linux sed命令详则

    sed命令 sed是一种流编辑器,它是文本处理中非常好的工具,能够完美的配合正则表达式使用,功能不同凡响。处理时,把当前的行储存在临时缓存区中,称为“模式空间”(pattern space),接着用sed命令处理缓存区中的内容,处理完成后,把缓存区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有改变,除非你使用重定向存储输出。Sed…

    2017-08-11
  • N22-第十四周作业

    系统的INPUT和OUTPUT默认策略为DROP; ~]# iptables -P INPUT DROP ~]# iptables -P OUTPUT DROP 1、限制本地主机的web服务器在周一不允许访问;新请求的速率不能超过100个每秒;web服务器包含了admin字符串的…

    Linux干货 2017-03-15
  • 包管理一:配置本地ISO的yum源

    故事背景:网上找了一个软件,但是这个软件需要依赖光盘上面的基础包,但是这个服务器又不能上网,怎么办? 方法:这里推荐配置本地ISO的yum源,然后yum localinstall xxx.rpm 1、yum的配置文件说明 配置文件: /etc/yum.conf:为所有仓库提供公共配置 /etc/yum.repos.d/*.repo:为仓库的指向提供配置 仓库…

    Linux干货 2016-01-05

评论列表(1条)

  • 马哥教育
    马哥教育 2017-01-03 17:11

    正则表达式很容易将人的水平区分开来,作业中完成的很不错,可以在工作学习中多加利用,再接再励。