马哥教育网络班21期+第四周课程练习

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

~]# cp -r /etc/skel /home/tuser1; chmod -R gx=--- /home/tuser1
[root@magelinux ~]# ls -la /home/tuser1/
total 28
drwx------. 2 root root 4096 Jul 28 08:52 .
drwxr-xr-x. 5 root root 4096 Jul 28 09:57 ..
-rw-------. 1 root root   18 Jul 28 08:52 .bash_logout
-rw-------. 1 root root  176 Jul 28 08:52 .bash_profile
-rw-------. 1 root root  124 Jul 28 08:52 .bashrc
-rw-------. 1 root root  171 Jul 28 08:52 .kshrc
-rw-------. 1 root root  658 Jul 28 08:52 .zshrc

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

~]# cat >>/etc/group <<EOF
> hadoop:x:3000:
> EOF
~]# tail -1 /etc/group
hadoop:x:3000:

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

[root@magelinux ~]# cat >>/etc/passwd <<EOF
> hadoop:x:3000:3000::/home/hadoop:/bin/bash
> EOF

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

[root@magelinux ~]# cp -r /etc/skel/ /home/hadoop ; chmod go=--- /home/hadoop
[root@magelinux ~]# ls -ld /home/hadoop/
drwx------. 2 root root 4096 Jul 28 09:57 /home/hadoop/

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

[root@magelinux ~]# chown -R hadoop:hadoop /home/hadoop/
[root@magelinux hadoop]# ls -la /home/hadoop/
total 28
drwx------. 2 hadoop hadoop 4096 Jul 28 09:57 .
drwxr-xr-x. 5 root   root   4096 Jul 28 09:57 ..
-rw-r--r--. 1 hadoop hadoop   18 Jul 28 09:57 .bash_logout
-rw-r--r--. 1 hadoop hadoop  176 Jul 28 09:57 .bash_profile
-rw-r--r--. 1 hadoop hadoop  124 Jul 28 09:57 .bashrc
-rw-r--r--. 1 hadoop hadoop  171 Jul 28 09:57 .kshrc
-rw-r--r--. 1 hadoop hadoop  658 Jul 28 09:57 .zshrc

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

[root@magelinux ~]# grep ^[sS] /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2047996 kB
[root@magelinux ~]# grep -i ^s /proc/meminfo    
SwapCached:            0 kB
SwapTotal:       2047996 kB

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

[root@magelinux ~]# grep -v  "/sbin/nologin"  /etc/passwd
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
gentoo:x:500:500::/home/gentoo:/bin/bash
hadoop:x:3000:3000::/home/hadoop:/bin/bash

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

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

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

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

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

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

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

[root@magelinux ~]# egrep "^#[[:space:]]{1,}[^[:space:]]+"  /etc/rc.d/rc.sysinit  
# /etc/rc.d/rc.sysinit - run once at boot time
# Taken in part from Miquel van Smoorenburg's bcheckrc.
# Check SELinux status

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

netstat -tan |egrep "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为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;

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

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

[root@magelinux ~]# grep ^[sS] /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2047996 kB
SwapFree:        2047996 kB
Shmem:               220 kB
Slab:             156856 kB
SReclaimable:      93320 kB
SUnreclaim:        63536 kB
[root@magelinux ~]# grep -i ^s /proc/meminfo      
SwapCached:            0 kB
SwapTotal:       2047996 kB
SwapFree:        2047996 kB
Shmem:               220 kB
Slab:             156836 kB
SReclaimable:      93312 kB
SUnreclaim:        63524 kB
[root@magelinux ~]# egrep -i ^s /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2047996 kB
SwapFree:        2047996 kB
Shmem:               220 kB
Slab:             156840 kB
SReclaimable:      93316 kB
SUnreclaim:        63524 kB

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

[root@magelinux ~]# grep -v "/sbin/nologin$" /etc/passwd
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
gentoo:x:500:500::/home/gentoo:/bin/bash
hadoop:x:3000:3000::/home/hadoop:/bin/bash
bash:x:3001:3001::/home/bash:/bin/bash
testbash:x:3002:3002::/home/testbash:/bin/bash
basher:x:3003:3003::/home/basher:/bin/bash

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

[root@magelinux ~]# grep "/bin/bash$" /etc/passwd |cut -d: -f1
root
gentoo
hadoop
bash
testbash
basher

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

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

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

(0)
微
上一篇 2016-08-02 10:54
下一篇 2016-08-02 10:55

相关推荐

  • #!/bin/bash # for i in $(ls /etc/rc.d/rc3.d/ | grep  "\<K");do     echo $i.stop    &nbs…

    Linux干货 2016-12-26
  • 学习宣言

    不妥协,不气馁,朝着自己的目标前进。

    Linux干货 2016-10-24
  • linux 小命令

    设置自动登录、设置网络自动连接、字体颜色

    2017-11-19
  • Linux基础知识及常用命令

    pwd:printing working directory -显示当前工作目录            [root@edu tmp]# pwd          &nbs…

    Linux干货 2016-09-15
  • LVS:三种模式的原理、调度算法、及应用介绍

    LVS三种模式原理(nat/dr/tun) LVS/NAT:   如上图,客户通过virtual IP (虚拟服务的IP地址,公网地址),访问网络服务时,请求报文到达调度器,调度器根据连接调度算法从一组真实服务器中选出一台服务器,将报文的目标地址VIP,改写成选定服务器的地址(RIP),报文的目标端口改写成选定服务器的相应端口,最后将修改…

    Linux干货 2016-10-30
  • 基于iptables mangle的lvs && lvs的持久连接

    一、lvs-dr类型:也称direct routing,简称为g(gatewaying);配置lvs-dr基于iptables mangle的实现方式  实验图:  地址规划:    VIP: 172.16.2.100    DIP: 172.16.2.13    RIP1:17…

    Linux干货 2015-06-30

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-02 11:49

    写的很好,排版也很棒,加油