第四周作业


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

[root@centos-7 ~]# cp -r /etc/skel /home/tuser1
[root@centos-7 ~]# chmod -R 700 /home/tuser1   
[root@centos-7 ~]# ls -al /home/tuser1/
total 12
drwx------.  4 root root  90 Nov 21 18:28 .
drwxr-xr-x. 16 root root 192 Nov 21 17:57 ..
-rwx------.  1 root root  18 Nov 21 17:57 .bash_logout
-rwx------.  1 root root 193 Nov 21 17:57 .bash_profile
-rwx------.  1 root root 231 Nov 21 17:57 .bashrc
drwx------.  4 root root  39 Nov 21 17:57 .mozilla
drwx------.  3 root root  78 Nov 21 18:28 skel

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

admins:x:2018:slackware
hadoop:x:8888:
[root@centos-7 ~]# echo "hadoop:x:8888:"  >> /etc/group

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

[root@centos-7 ~]# echo "hadoop:x:8888:8888::/home/hadoop:/bin/bash" >> /etc/passwd
[root@centos-7 ~]# grep 'hadoop' /etc/passwd                                       
hadoop:x:8888:8888::/home/hadoop:/bin/bash

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

[root@centos-7 ~]# cp -r /etc/skel /home/hadoop
[root@centos-7 ~]# chown  -R hadoop /home/hadoop
[root@centos-7 ~]# chgrp -R hadoop  /home/hadoop
[root@centos-7 ~]# chmod -R 700 /home/hadoop 

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

[root@centos-7 hadoop]# chown -R hadoop  /home/hadoop      
[root@centos-7 hadoop]# chgrp -R hadoop /home/hadoop 
[root@centos-7 hadoop]# ls -al
total 12
drwx------.  4 hadoop hadoop  90 Nov 21 20:13 .
drwxr-xr-x. 17 root   root   206 Nov 21 19:33 ..
-rwx------.  1 hadoop hadoop  18 Nov 21 19:33 .bash_logout
-rwx------.  1 hadoop hadoop 193 Nov 21 19:33 .bash_profile
-rwx------.  1 hadoop hadoop 231 Nov 21 19:33 .bashrc
drwx------.  4 hadoop hadoop  39 Nov 21 19:33 .mozilla
drwx------.  3 hadoop hadoop  78 Nov 21 20:13 skel

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

[root@centos-7]# grep "^[Ss]" /proc/meminfo
[root@centos-7]# grep -i ^'s' /proc/meminfo 

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

[root@centos-7 hadoop]# grep '/sbin/nologin'$ /etc/passwd | cut -d: -f1

8.显示/etc/passwd文件中默认shell为/bin/bash用户

[root@centos-7 hadoop]# grep '/bin/bash'$ /etc/passwd | cut -d: -f1 

9.找出/etc/paawd文件中的一位数或两位数

 grep "\<[0-9]\{1,2\}\>" /etc/passwd

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

[root@centos-7 hadoop]# grep "^[[:space:]]\{1,\}" /boot/grub/grub.conf

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

[root@centos-7 hadoop]# grep "^#[[:space:]]\{1,\}[^[:space:]]\{1,\}" /etc/rc.d/rc.local      
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.    

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

[root@centos-7 hadoop]# netstat -tan | grep "\\|[[:space:]]\{0,\}$"

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

[root@centos-7 ~]# 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:1003:1007::/home/bash:/bin/bash
sh:x:1006:1010::/home/sh:/bin/bash
nologin:x:1007:1011::/sbin/nologin:/sbin/nologin

你可能感兴趣的:(第四周作业)