用户创建过程&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

相关推荐

  • grup修复与安装操作介绍

    一、bgru Stage1的安装     1、stage1存储在MBR的前446字节,首先破坏。使用dd命令     2、使用grub-install命令安装修复grub stage1     3、使用grub命令修复 二、进入救援模式,修改grub     1、先破坏grub …

    Linux干货 2016-06-03
  • N25第一周博客作业

    本文主要阐述了以下几个知识点: l  计算机的组成及功能; l  介绍各不同发行版的linux及其联系; l  描述linux的哲学思想,及其本人对其个人理解; l  介绍一些linux基本命令及相关选项; l  如何在linux上使用帮助命令; l  罗列出发行版linux上的一些基础目录及其功用…

    Linux干货 2016-11-29
  • Linux管理目录和文件命令

     管理目录命令: pwd:显示当前目录 Cd:   改变当前目录 ls:    查看目录下的内容 rmdir: 删除目录 管理文件命令: cat: 查看文件内容 cp: 复制文件内容 grep:在文件中查找某字符 touch:创建文件 rm&nbsp…

    2016-03-05
  • 正则表达式及其用法

    正则表达式及其用法 1.   什么是正则表达式 正则表达式是Global search REgular expression and Print out the line的缩写。是一类用字符所书写的模式,其中许多字符并不表示其字面意义,而是表达控制或通配等功能。 在Linux中,用正则表达式搜索文本的常用命令: grep: 使用基本正则表…

    Linux干货 2015-09-14
  • 权限

    用户组和管理权限

    2017-11-30
  • Linux发展史

    日期:2016-10-12  Bell,MIT与GE的『Multics』系统     早期的计算机还很不普遍,除非是军事或者高科技用途,或者学术单位的学术研究,否则真的很难接触到。而且计算机架构很难使用。那个时候,程序设计者必须先将程序相关的信息在读卡纸上面打洞然后将读卡纸插入卡片阅读机来将信息读入主机中运算…

    Linux干货 2016-10-14

评论列表(1条)

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

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