N25_第四周作业(补)

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

[root@EASTED tmp]# cp -r /etc/skel/ /home/tuser1/
[root@EASTED tmp]# cp -r /etc/skel/ /home/tuser1/
[root@EASTED tmp]# ls -al /home/tuser1/
总用量 4
drwx------.  3 root root   17 1月   2 21:31 .
drwxr-xr-x. 10 root root 4096 1月   2 21:29 ..
drwx------.  3 root root   74 1月   2 21:31 skel

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

hadoop:x:1004:
:wq

[root@EASTED tmp]# echo "hadoop:x:1004:" >> /etc/group
[root@EASTED tmp]# cat /etc/group
hadoop:x:1004:

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

[root@EASTED tmp]# vi /etc/passwd
hadoop:x:1004:1004::/home/hadoop:/bin/bash
-- INSERT --

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

[root@EASTED tmp]# cp -r /etc/skel/ /home/hadoop
[root@EASTED tmp]# chmod 700 /home/hadoop/
[root@EASTED tmp]# ls -al /home/hadoop/
总用量 16
drwx------.  3 root root   74 1月   2 21:59 .
drwxr-xr-x. 11 root root 4096 1月   2 21:59 ..
-rw-r--r--.  1 root root   18 1月   2 21:59 .bash_logout
-rw-r--r--.  1 root root  193 1月   2 21:59 .bash_profile
-rw-r--r--.  1 root root  231 1月   2 21:59 .bashrc
drwxr-xr-x.  4 root root   37 1月   2 21:59 .mozilla
[root@EASTED tmp]#

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

[root@EASTED tmp]# chown -R hadoop:hadoop /home/hadoop/
[root@EASTED tmp]# ls -al /home/hadoop/
总用量 16
drwx------.  3 hadoop hadoop   74 1月   2 21:59 .
drwxr-xr-x. 11 root   root   4096 1月   2 21:59 ..
-rw-r--r--.  1 hadoop hadoop   18 1月   2 21:59 .bash_logout
-rw-r--r--.  1 hadoop hadoop  193 1月   2 21:59 .bash_profile
-rw-r--r--.  1 hadoop hadoop  231 1月   2 21:59 .bashrc
drwxr-xr-x.  4 hadoop hadoop   37 1月   2 21:59 .mozilla

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

[root@EASTED tmp]# grep ^[sS] /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              9788 kB
Slab:             116176 kB
SReclaimable:      58352 kB
SUnreclaim:        57824 kB
[root@EASTED tmp]# grep -i ^s /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              9788 kB
Slab:             116188 kB
SReclaimable:      58360 kB
SUnreclaim:        57828 kB

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

[root@EASTED tmp]# 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
lyf:x:1000:1000:LYF:/home/lyf:/bin/bash
LiangYF:x:1001:1001::/home/LiangYF:/bin/bash
slackware:x:1002:1002::/home/slackware:/bin/tcsh
houyuan:x:1003:1003::/home/houyuan:/bin/bash
hadoop:x:1004:1004::/home/hadoop:/bin/bash

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

[root@EASTED tmp]# grep  "/bin/bash$" /etc/passwd
root:x:0:0:root:/root:/bin/bash
lyf:x:1000:1000:LYF:/home/lyf:/bin/bash
LiangYF:x:1001:1001::/home/LiangYF:/bin/bash
houyuan:x:1003:1003::/home/houyuan:/bin/bash
hadoop:x:1004:1004::/home/hadoop:/bin/bash

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

[root@EASTED tmp]# grep  "\<[0-9]\{1,2\}\>"  /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
saslauth:x:993:76:Saslauthd user:/run/saslauthd:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin

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

[root@EASTED grub]# grep " ^[[:space:]]+"  /boot/grub/grub.conf

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

[root@EASTED grub]# grep "^#[[:space:]]+[^[:space:]]" /etc/rc.d/rc.sysinit

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

[root@EASTED grub]# netstat -tan | grep  "LISTEN[[:space:]]*$"
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN     
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@EASTED ~]# grep "^\([[:alnum:]]\+[^:]\>\).*\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:1006:1006::/home/bash:/bin/bash
nologin:x:1012:1012::/home/nologin:/sbin/nologin

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

[root@EASTED tmp]# grep ^[sS] /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              9788 kB
Slab:             116176 kB
SReclaimable:      58352 kB
SUnreclaim:        57824 kB

[root@EASTED tmp]# grep -i ^s /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              9788 kB
Slab:             116188 kB
SReclaimable:      58360 kB
SUnreclaim:        57828 kB

[root@EASTED ~]# grep -E "^(s|S)" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              9788 kB
Slab:             116384 kB
SReclaimable:      58500 kB
SUnreclaim:        57884 kB

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

(0)
LYFLYF
上一篇 2017-01-02
下一篇 2017-01-03

相关推荐

  • 8.16

    for 循环是相对比较简单的循环,任何一个循环里面都可以嵌套循环,用for可以解决简单逻辑上的任何循环 。 有两种基本格式:for i in " ";do         或者dor((i=0;i<=9;i++))可以嵌套if或者while等循环 if循环。最重要的是判断的条件,if意为如果什…

    Linux干货 2016-08-19
  • shell脚本的练习

    1、写一个脚本,使用ping命令探测172.16.250.1-172.16.250.254之间的所有主机的在线状态1、写一个脚本,使用ping命令探测172.16.250.1-172.16.250.254之间的所有主机的在线状态  在线的主机使用绿色显示  不在线的主机使用红色显示 #!/bin/bash for i in {1..254};do { ip=…

    2017-09-17
  • bash脚本编程class2

    bash脚本class2—循环语句的使用      一.三种循环语句以及其具体使用方法   我们知道,在shell脚本编程过程中,为了实现逻辑关系的运算,有三种执行命令的顺序:顺序执行,选择执行,循环执行。通过if,case这类语句可以实现条件筛选后执行命令,这次课程中所学的主要知识点为循环语句的三种使用方式:for,…

    Linux干货 2016-08-19
  • ansible高级应用

    上一篇博客介绍了ansible的基础应用Modules,博客地址 http://www.178linux.com/14860 。这次介绍下Ansible的另一个核心模块Playbooks。   Ansible的核心模块:     Ansible core:   &nbs…

    Linux干货 2016-04-18
  • 0812 find 作业

    0812作业 1、查找/var目录下属主为root,且属组为mail的所有文件 [root@CentOS 7 ~]# find /var -user root -a -group mail /var/spool/mail [root@CentOS 7&nbsp…

    Linux干货 2016-08-13
  • 高级文件系统管理之磁盘配额及RAID的运用

    本章内容 设定文件系统配额 设定和管理软RAID设备 一,概述 配置配额系统: 综述 在内核中执行 以文件系统为单位启用 磁盘配额最小单位是以文件系统为单位启用,就是一个挂载点,而不能以目录为单位 对不同组或者用户的策略不同 根据块或者节点进行限制 执行软限制(soft limit) 硬限制(hard limit) 初始化 分区挂载选项:usrquota、g…

    Linux干货 2016-09-07