用户创建过程&grep练习

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

    ~]# cp -r /etc/skel /home/tuser1
    ~]# ls -la /home/tuser1
    total 20
    drwxr-xr-x.  3 root root   87 Oct 17 08:47 .
    drwxr-xr-x. 27 root root 4096 Oct 17 08:47 ..
    -rw-r–r–.  1 root root   18 Oct 17 08:47 .bash_logout
    -rw-r–r–.  1 root root  193 Oct 17 08:47 .bash_profile
    -rw-r–r–.  1 root root  231 Oct 17 08:47 .bashrc
    drwxr-xr-x.  4 root root   37 Oct 17 08:47 .mozilla
    -rw-r–r–.  1 root root  658 Oct 17 08:47 .zshrc
    ~]# chmod -R g-r,o-r /home/tuser1
    ~]# ls -la /home/tuser1
    total 20
    drwx–x–x.  3 root root   87 Oct 17 08:47 .
    drwxr-xr-x. 27 root root 4096 Oct 17 08:47 ..
    -rw——-.  1 root root   18 Oct 17 08:47 .bash_logout
    -rw——-.  1 root root  193 Oct 17 08:47 .bash_profile
    -rw——-.  1 root root  231 Oct 17 08:47 .bashrc
    drwx–x–x.  4 root root   37 Oct 17 08:47 .mozilla
    -rw——-.  1 root root  658 Oct 17 08:47 .zshrc
    
2、编辑/etc/group文件,添加组hadoop。

    vim /etc/group
    编辑模式下键入G进入文件尾
    键入o进行下行输入hadoop:x:3000:
    esc进入编辑模式
    ZZ保存并退出

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

    vim /etc/passwd
    hadoop:x:3000:3000::/home/hadoop:/bin/bash
    ~]# id hadoop
    uid=3000(hadoop) gid=3000(hadoop) groups=3000(hadoop)

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

    ~]# cp -r /etc/skel /home/hadoop
    ~]# ls -la /home/hadoop
    total 20
    drwxr-xr-x.  3 root root   87 Oct 17 09:07 .
    drwxr-xr-x. 27 root root 4096 Oct 17 09:07 ..
    -rw-r–r–.  1 root root   18 Oct 17 09:07 .bash_logout
    -rw-r–r–.  1 root root  193 Oct 17 09:07 .bash_profile
    -rw-r–r–.  1 root root  231 Oct 17 09:07 .bashrc
    drwxr-xr-x.  4 root root   37 Oct 17 09:07 .mozilla
    -rw-r–r–.  1 root root  658 Oct 17 09:07 .zshrc
    ~]# chmod -R g-r,o-r /home/hadoop
    ~]# ls -la /home/hadoop
    total 20
    drwx–x–x.  3 root root   87 Oct 17 09:07 .
    drwxr-xr-x. 27 root root 4096 Oct 17 09:07 ..
    -rw——-.  1 root root   18 Oct 17 09:07 .bash_logout
    -rw——-.  1 root root  193 Oct 17 09:07 .bash_profile
    -rw——-.  1 root root  231 Oct 17 09:07 .bashrc
    drwx–x–x.  4 root root   37 Oct 17 09:07 .mozilla
    -rw——-.  1 root root  658 Oct 17 09:07 .zshrc

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

    ~]# chown -R hadoop.hadoop /home/hadoop
    ~]# ls -la /home/hadoop
    total 20
    drwx–x–x.  3 hadoop hadoop   87 Oct 17 09:07 .
    drwxr-xr-x. 27 root   root   4096 Oct 17 09:07 ..
    -rw——-.  1 hadoop hadoop   18 Oct 17 09:07 .bash_logout
    -rw——-.  1 hadoop hadoop  193 Oct 17 09:07 .bash_profile
    -rw——-.  1 hadoop hadoop  231 Oct 17 09:07 .bashrc
    drwx–x–x.  4 hadoop hadoop   37 Oct 17 09:07 .mozilla
    -rw——-.  1 hadoop hadoop  658 Oct 17 09:07 .zshrc

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

    ~]# cat /proc/meminfo | grep "^[sS]"
    SwapCached:0 kB
    SwapTotal:   2097148 kB
    SwapFree:2097148 kB
    Shmem:  9292 kB
    Slab:  82384 kB
    SReclaimable:  31540 kB
    SUnreclaim:50844 kB
    ~]# cat /proc/meminfo | grep -i "^s"
    SwapCached:0 kB
    SwapTotal:   2097148 kB
    SwapFree:2097148 kB
    Shmem:  9292 kB
    Slab:  82392 kB
    SReclaimable:  31540 kB
    SUnreclaim:50852 kB

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

    ~]# cat /etc/passwd | grep -v "/sbin\/nologin$" | cut -d: -f1
    root
    sync
    …

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

    ~]# cat /etc/passwd | grep "\/bin\/bash$" | cut -d: -f1
    root
    void
    archlinux
    …

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

    ~]# cat /etc/passwd | grep "\<[0-9]\>\|\<[0-9][0-9]\>"
    root:x:0:0:root:/root:/bin/bash
    bin:x:1:1:bin:/bin:/sbin/nologin
    daemon:x:2:2:daemon:/sbin:/sbin/nologin
    …
    
    
    ~]# cat /etc/passwd | grep "\<[0-9]\{1,2\}\>"
    root:x:0:0:root:/root:/bin/bash
    bin:x:1:1:bin:/bin:/sbin/nologin
    …

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

    ~]# cat /boot/grub/grub.conf | grep "^[[:space:]]\+"
    root (hd0,0)
    kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUK
    S rd_NO_MD rd_LVM_LV=VolGroup/lv_swap crashkernel=auto.UTF-8 rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quietinitrd /initramfs-2.6.32-431.el6.x86_64.img

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

    ~]# cat /etc/rc.d/rc.sysinit | grep "^#[[:space:]]\+\.*[^[:space:]]\+"
    # /etc/rc.d/rc.sysinit – run once at boot time
    # Taken in part from Miquel van Smoorenburg's bcheckrc.
    # Check SELinux status
    # Print a text banner.
    # Only read this once.
    …

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

    ~]# netstat -tan | grep "LISTEN[[:space:]]*$"
    tcp0  0 0.0.0.0:111 0.0.0.0:*   LISTEN 
    tcp0  0 0.0.0.0:22  0.0.0.0:*   LISTEN 
    tcp0  0 127.0.0.1:631   0.0.0.0:*   LISTEN 
    tcp0  0 127.0.0.1:250.0.0.0:*   LISTEN 
    tcp0  0 127.0.0.1:6010  0.0.0.0:*   LISTEN 
    tcp0  0 0.0.0.0:59740   0.0.0.0:*   LISTEN 
    tcp0  0 :::111  :::*LISTEN 
    tcp0  0 :::22   :::*LISTEN 
    tcp0  0 ::1:631 :::*LISTEN 
    tcp0  0 ::1:25  :::*LISTEN 
    tcp0  0 ::1:6010:::*LISTEN 
    tcp0  0 :::42689:::*LISTEN

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

    ~]# useradd bash
    ~]# useradd testbash
    ~]# useradd basher
    ~]# useradd nologin
    ~]# usermod -s /sbin/nologin nologin
    
    ~]#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:500:500::/home/bash:/bin/bash
    nologin:x:503:503::/home/nologin:/sbin/nologin
    
    ~]# 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:500:500::/home/bash:/bin/bash
    nologin:x:503:503::/home/nologin:/sbin/nologin

原创文章,作者:N23-苏州-void,如若转载,请注明出处:http://www.178linux.com/52342

(0)
N23-苏州-voidN23-苏州-void
上一篇 2016-10-17
下一篇 2016-10-17

相关推荐

  • 五大主流数据库模型

    导读:无论是关系型数据库还是非关系型数据库,都是某种数据模型的实现。本文将为大家简要介绍5种常见的数据模型,让我们来追本溯源,窥探现在流行的数据库解决方案背后的神秘世界。 什么是数据模型? 访问数据库中的数据取决于数据库实现的数据模型。数据模型会影响客户端通过API对数据的操作。不同的数据模型可能会提供或多或少的功能。一般而言,数据模型不会直接提供过多的功能…

    Linux干货 2015-04-04
  • Linux基础解析;echo;man;centos;runlevel;PS1;screen;shell 倒三角;date -d等命令—-fazion blog at22.July

    Linux基础解析 fazionlan blog in 178Linux.July 20nd. 内核、版本信息 # uname -a                 &n…

    Linux干货 2016-07-29
  • N25期–第十四周作业

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

    Linux干货 2017-04-10
  • Memcached + MSM 实现Tomcat Session保持

    Memcached + MSM 实现Tomcat Session保持 tomcat memcached 前言 Memcached介绍 MSM介绍 实验拓扑 实验环境 实验步骤 安装配置Tomcat 安装配置Nginx负载均衡 安装配置Memcached + MSM 总结 前言 上篇文章我们实现了session sticky和session clus…

    2016-04-22
  • Shell脚本编程

    Shell脚本编程

    2017-09-20
  • M20-1 8月5号作业

    作业:    1、取本机IP地址;    2、取各分区利用率的数值;    3、统计/etc/init.d/functions 文件中每个单词出现的次数,并按频率从高到低显示;    4、/etc/rc.d/init.d/functions或/etc/rc.d/init.d/fu…

    Linux干货 2016-08-15

评论列表(1条)

  • 马哥教育
    马哥教育 2016-10-20 19:39

    完成的很好,学有余力的话,可以把一些题目换个正则表达式来完成,加油。