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

相关推荐

  • http协议

    Web Service概述 web服务时一种应用程序的服务,它所提供的最主要的信息是一种超文本标记语言(HTML)、多媒体资源(如:视频、图片、音乐等)。HTML是一种纯文字的文本信息,通过所谓的标签来规范所要显示的内容格式,在客户端通过浏览器的形式对HTML及多媒体资源进行解析,然后呈现在终端上。主要由http和https协议实现 http协议概述 HTT…

    Linux干货 2016-10-28
  • 文件查找与压缩-1

       1、 locate命令(非实时查找即数据库查找) 1)、查询系统上预建的文件索引数据库/var/lib/mlocate/mlocate.db      依赖于事先构建的索引;索引的构建是在系统较为空闲时自动进行( 周期性任务) 或者管理员手动更新数据库即是执行#updatedb命令;引构建过程…

    Linux干货 2016-08-15
  • Linux-运维之半自动化安装系统

    CentOS系统安装             系统启动流程: bootloader–>kernel(initramfs)–>rootfs–>/sbin/init 安装程序启动过程:         &nbs…

    2017-07-24
  • yum用法第一篇-简介及常见用法使用总结

    一、简介     yum( 全称为:Yellow dog Updater, Modified),是红帽(RedHat)家族(RedHat、Fedora、CentOS)中的前端shell的软件包管理器,主要基于对RPM包的管理,能够根据配置文件(类似于svn资源库配置文件)从指定的服务器自动下载RPM包进行安装,其最大的优势就是可…

    Linux干货 2015-09-22
  • shutil,csv,ini

    序列化和反序列化笔记

    2017-10-29
  • 26期全程班-第六周博客作业

    请详细总结vim编辑器的使用并完成以下练习题 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; # cp /etc/rc.d/rc.sysinit /tmp # vim /tmp/rc.sysinit :%s@^\([[:space:]]\+\)@#\1@g 2…

    Linux干货 2017-03-07

评论列表(1条)

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

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