第四周作业:etc/skel实战联系

第四周作业

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

 [root@localhost ~]# cp -r /etc/skel/ /home/tuser1/  #复制目录
 [root@localhost ~]# chmod -R go=---  /home/tuser1   #调整属组及其他用户没有任何权限

2、编辑/etc/group文件,添加组hadoop。

 [root@localhost ~] vim /etc/group
 #在编辑模式下按     G, o
 #在插入模式下输入   hadoop:x:506
 #按esc退出插入模式,输入wq保存并退出文本

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

 [root@localhost ~]# vim /etc/passwd
  #在编辑模式下按     G, o
  #在插入模式下输入  hadoop:x:506:506::/home/hadoop:/bin/bash
  #按esc退出插入模式,输入wq保存并退出文本

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

  [root@localhost ~]# cp -r /etc/skel/ /home/hadoop/
  [root@localhost ~]# chmod -R go=--- /home/hadoop/

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

  [root@localhost ~]# chown hadoop:hadoop /home/hadoop/
    #验证是否成功修改
   [root@localhost home]# ls -adl /home/hadoop/
   drwx------. 2 hadoop hadoop 59 3月  20 13:17 /home/hadoop/
   [root@localhost home]# ls -al /home/hadoop/
   总用量 16
   drwx------.  2 hadoop hadoop   59 3月  20 13:17 .
   drwxr-xr-x. 12 root   root   4096 4月  12 22:16 ..
   -rw-r--r--.  1 hadoop hadoop   18 3月   6 2015 .bash_logout
   -rw-r--r--.  1 hadoop hadoop  193 3月   6 2015 .bash_profile
   -rw-r--r--.  1 hadoop hadoop  231 3月   6 2015 .bashrc

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

    [root@localhost home]# grep "^[S|s]" /proc/meminfo 
    SwapCached:            0 kB
    SwapTotal:       2097148 kB
    SwapFree:        2097148 kB
    Shmem:             13036 kB
    Slab:             108008 kB
    SReclaimable:      60564 kB
    SUnreclaim:        47444 kB
    [root@localhost home]# grep -i "^s" /proc/meminfo
    SwapCached:            0 kB
    SwapTotal:       2097148 kB
    SwapFree:        2097148 kB
    Shmem:             13036 kB
    Slab:             108008 kB
    SReclaimable:      60564 kB
    SUnreclaim:        47444 kB

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

   [root@localhost home]# cat /etc/passwd | grep -v "/sbin/nologin$" |cut -d: -f1
   root
   sync
   shutdown
   halt
   frdora
   gentoo
   fedora
   iee
   eee
   iie
   hadoop
   mageia
   slackware

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

    [root@localhost home]# cat /etc/passwd | grep "/bin/bash$" |cut -d: -f1
    root
    gentoo
    fedora
    iee
    eee
    iie
    hadoop
    mageia

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

 [root@localhost home]# cat /etc/passwd | grep -o "\<[0-9]\{1,2\}\>"
 0
 0
 1
 1
 2
 2
 3
 4
 4
 7
 5
 0
 6
 0
 7
 0
 8
 12
 11
 0
 12
 14
 50
 99
 99
 81
 81
 59
 59
 89
 89
 74
 74

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

 [root@localhost ~]# cat /boot/grub/grub.conf  |grep "^[[:space:]]\+" 
    root (hd0,0)
    kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=UUID=9e52c88a-8b61-444c-a78a-ac642700cf99 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
    initrd /initramfs-2.6.32-431.el6.x86_64.img

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

 **[root@localhost ~]# 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.
 # Initialize hardware
 # Set default affinity
 # Load other user-defined modules
 # Load modules (for backward compatibility with VARs)
 # Configure kernel parameters
 # Set the hostname.
 。。。。。

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

  [root@localhost ~]# netstat -tan | grep "LISTEN[[:space:]]*$"
  tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
  tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
  tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
  tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
  tcp        0      0 0.0.0.0:60774               0.0.0.0:*                   LISTEN      
  tcp        0      0 :::111                      :::*                        LISTEN      
  tcp        0      0 :::22                       :::*                        LISTEN      
  tcp        0      0 ::1:631                     :::*                        LISTEN      
  tcp        0      0 ::1:25                      :::*                        LISTEN      
  tcp        0      0 :::38663                    :::*                        LISTEN 

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

 首先添加用户:
 [root@localhost ~] useradd bash
 [root@localhost ~] useradd testrbash
 [root@localhost ~] useradd bbasher
 [root@localhost ~] useradd -s /sbin/nologin nologin

 找出当前系统上其用户名和默认shell相同的用户的信息:
 [root@localhost ~]# cat /etc/passwd | grep "^\(\<[[:alnum:]]\+\>\).*\<\1$"
 sync:x:5:0:sync:/sbin:/bin/sync
 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
 halt:x:7:0:halt:/sbin:/sbin/halt
 nologin:x:503:503::/home/nologin:/sbin/nologin
 bash:x:504:504::/home/bash:/bin/bash

 

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/95822

(0)
上一篇 2018-04-13 11:30
下一篇 2018-04-13 15:39

相关推荐

评论列表(1条)

  • 马哥教育
    马哥教育 2018-04-26 19:31

    作业没问题。