用户创建过程&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)
上一篇 2016-10-17 08:37
下一篇 2016-10-17 19:59

相关推荐

  • net25 第16周作业

    1、源码编译安装LNMP架构环境; yum groupinstall -y ‘Development Tools’ ‘Server Platform Development’ 编译nginx ~]# yum install -y openssl-devel pcre-devel ~]# useradd ngin…

    Linux干货 2017-05-15
  • linux基础之磁盘管理

    linux基础之磁盘管理 学习linux,数据维护和管理是重中之重,而数据大部分存放在硬盘当中,因此,熟练掌握磁盘的使用和管理是运维人员的基础要求。那么,linux系统包括哪些知识点呢? 下面,我们就详细阐述下Linux中磁盘的分区、格式化,以及一些磁盘的高级用法:磁盘配额、RAID阵列和LVM 一、硬盘 随着技术的进步,人类社会的不断发展。硬盘也经历了几代…

    Linux干货 2017-03-19
  • corosync+pacemaker+drbd+mysql来实现mysql的高可用和数据的同步

    实现拓扑图: 实验流程: 先对两主机安装上corosync和pacemaker 两主机安装drbd服务,并且设置好drbd的组设备 选择drbd主节点上,进行数据库的初始化 进行资源的定义和配置 测试 实验前,我们还需要做一些准备工作: 1、时间必须保持同步   使用ntp服务器 2、节点必须名称互相通信    解析节点名称 &…

    Linux干货 2015-11-10
  • linux用户与用户组详解

    LINUX用户与用户组详解     1,用户和用户组文件   在linux中,用户帐号,用户密码,用户组信息和用户组密码均是存放在不同的配置文件中的。分别是 passed gpassd shadow group 中。   在linux系统中,所创建的用户帐号和其相关信息(密码除外)均是存放在/etc…

    Linux干货 2017-07-22
  • 磁盘阵列RAID

          RAID全名为Redundant Arrary of lnexpensive Disks,是一种可以提高磁盘IO和提高磁盘耐用性   的磁盘阵列。       RAID的实现方式一般分为三种:             …

    Linux干货 2016-06-22
  • 文本处理工具初探

    作为一个系统管理员,文本处理功能是经常使用的,熟练地使用各种文本工具有助于提高工作效率,从繁忙的工作中早点解脱。下面就来介绍处理文本的常用命令。 处理文本的命令大致分为:        查看文件内容:cat、less、more       …

    Linux干货 2016-08-07

评论列表(1条)

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

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