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

相关推荐

  • grep,egrep及相应的正则表达式用法详解

    目录 1、grep简介     1.1、grep是什么     1.2、grep使用格式     1.3、grep常用选项 2、正则表达式与grep     2.1、正则表达式简介  &nb…

    系统运维 2016-08-22
  • 软Raid

    软RAID     一.概念 RAID是多个磁盘合成一个“阵列”来提供更好的性能、冗余、或者两者都提供。 二.作用 提高IO能力: 磁盘并行读写 提高冗余来实现 :磁盘冗余来实现 三.实现方式 外接式磁盘阵列:通过扩展卡提供适配能力 内接式RAID:主板集成RAID控制器 软件RAID:通过OS实现(今天的重点) 四.RAID级别 1. …

    2017-08-29
  • vim编辑器

                在Linux的学习中,无论是编写脚本还是修改文件内容,我们最经常用的就是vim编辑器.vim编辑器功能十分强大,如今不仅仅只应用在Linux中.今天就来介绍一下vim编辑器的功能 进入和退出vim     进入:   在终端输入vim 文件名 ,…

    Linux干货 2017-08-05
  • 记事本操作的小小小技巧

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://jeffyyko.blog.51cto.com/28563/140063       大家在查看文本文件的时候,如果内容很多,想快速到达某一位置可能比较麻烦,这时如果按住shift,再点击右侧…

    Linux干货 2015-03-26
  • 第五周博客作业

      感觉进入了年底,明显的时间不够,不管怎么说,还是要努力跟上学习的进度,不能给自己松懈找借口!  1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; [root@localhost ~]# grep "^[[:space:]]\+" /boot/grub/grub.co…

    Linux干货 2017-01-03
  • shell通配符与正则表达式

        通配符是系统level的 而正则表达式需要相关工具的支持: egrep, awk, vi, perl。在文本过滤工具里,都是用正则表达式,比如像awk,sed等,是针对文件的内容的。通配符多用在文件名上,比如查找find,ls,cp,等等。 1.通配符       (1)…

    Linux干货 2016-02-28

评论列表(1条)

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

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