马哥教育网络班22期+第4周课程练习

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

[root@localhost ~]# cp -r /etc/skel /home/tuser1
[root@localhost ~]# chmod -R 600 /home/tuser1/
[root@localhost ~]# ls -al /home/tuser1/
总用量 12
drw-------. 3 root root  74 9月   3 21:11 .
drwxr-xr-x. 8 root root  90 9月   3 21:11 ..
-rw-------. 1 root root  18 9月   3 21:11 .bash_logout
-rw-------. 1 root root 193 9月   3 21:11 .bash_profile
-rw-------. 1 root root 231 9月   3 21:11 .bashrc
drw-------. 4 root root  37 9月   3 21:11 .mozilla

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

[root@localhost ~]# vi /etc/group
hadoop:x:2021:

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

[root@localhost ~]# vi /etc/passwd
hadoop:x:2021:2021::/home/hadoop:/bin/bash

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

[root@localhost ~]# cp -r /etc/skel/ /home/hadoop
[root@localhost ~]# chmod -R 600 /home/hadoop
[root@localhost ~]# ls -al /home/hadoop
总用量 12
drw-------. 3 root root  74 9月   3 21:21 .
drwxr-xr-x. 9 root root 103 9月   3 21:21 ..
-rw-------. 1 root root  18 9月   3 21:21 .bash_logout
-rw-------. 1 root root 193 9月   3 21:21 .bash_profile
-rw-------. 1 root root 231 9月   3 21:21 .bashrc
drw-------. 4 root root  37 9月   3 21:21 .mozilla

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

[root@localhost ~]# chown -R hadoop.hadoop /home/hadoop/
[root@localhost ~]# ls -al /home/hadoop/
总用量 12
drw-------. 3 hadoop hadoop  74 9月   3 21:21 .
drwxr-xr-x. 9 root   root   103 9月   3 21:21 ..
-rw-------. 1 hadoop hadoop  18 9月   3 21:21 .bash_logout
-rw-------. 1 hadoop hadoop 193 9月   3 21:21 .bash_profile
-rw-------. 1 hadoop hadoop 231 9月   3 21:21 .bashrc
drw-------. 4 hadoop hadoop  37 9月   3 21:21 .mozilla

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

[root@localhost ~]# grep "^[Ss]" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             10216 kB
Slab:             325872 kB
SReclaimable:     239960 kB
SUnreclaim:        85912 kB
[root@localhost ~]# grep -i "^s" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             10216 kB
Slab:             325904 kB
SReclaimable:     239960 kB
SUnreclaim:        85944 kB

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

[root@localhost ~]# grep -v "/sbin/nologin$" /etc/passwd
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
admin:x:1001:1001:Johnny Chung:/home/admin:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016::/home/slackware:/bin/tcsh
openstack:x:3003:2019::/home/openstack:/bin/bash
hadoop:x:2021:2021::/home/hadoop:/bin/bash

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

[root@localhost ~]# grep  "/bin/bash$" /etc/passwd | cut -d: -f1
root
admin
mageia
openstack
hadoop

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

[root@localhost ~]# egrep "\<[0-9]{1,2}\>" /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
saslauth:x:993:76:Saslauthd user:/run/saslauthd:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin

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

[root@localhost ~]# grep "^[[:space:]]\+" /boot/grub/grub.conf
  line start from space
    line start from space

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

[root@localhost ~]# grep "^#[[:space:]]\+[^[:space:]]" /boot/grub/grub.conf
# /etc/fstab
# Created by anaconda on Tue Aug  9 09:06:24 2016
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

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

[root@localhost ~]# netstat -tan | egrep "LISTEN[[:space:]]+$"
tcp        0      0 192.168.122.1:53        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    
tcp6       0      0 :::22                   :::*                    LISTEN    
tcp6       0      0 ::1:631                 :::*                    LISTEN    
tcp6       0      0 ::1:25                  :::*                    LISTEN

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

[root@localhost ~]# egrep "^([[:alpha:]]+\>).*\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:3004:3004::/home/bash:/bin/bash
nologin:x:3007:3007::/home/nologin:/sbin/nologin

原创文章,作者:zhangxiaola,如若转载,请注明出处:http://www.178linux.com/43153

(0)
zhangxiaolazhangxiaola
上一篇 2016-09-05 08:52
下一篇 2016-09-05 08:52

相关推荐

  • nginx基础模块

    目录: nginx基础模块: 1.ngx_http_access_module模块: 2.ngx_http_auth_basic_module模块 3.ngx_http_stub_status_module模块 4.ngx_http_log_module模块 5.ngx_http_gzip_module: 6.ngx_http_ssl_module模块: 7…

    Linux干货 2017-08-08
  • 第8天磁盘管理练习—增加SWAP分区

          SWAP交换空间,指在物理内存不够用时,充当虚拟内存使用。在实际操作中,使用1-2G的一个分区并指定分区类型为SWAP,挂载至SWAP来使用。 一、新增分区 fdisk /dev/sda n     #新增加分区 t   &nb…

    Linux干货 2016-07-04
  • Bash Shell之数组简介

    Bash Shell之数组简介   一、数组基本概念   数组是内存中的存储空间,连续的多个存储单元;bash中只支持一维数组,支持稀疏格式 ,参数个数没有限制。 二、数组基本语法格式   1、声明一个数组          declare…

    Linux干货 2015-05-11
  • sed命令、crontab任务、简单脚本练习(21期网络班第六周博客作业)

    vim使用: 直接使用sed模式空间演示,基本语法与vim命令模式类似(需注意vim默认定界为当前行,一般需要在前面加1,$定界为全文,而sed不需要) 1、 复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#;      sed &#03…

    Linux干货 2016-08-22
  • 第七周 系统启动维护管理

    1、简述linux操作系统启动流程 2、简述grub启动引导程序配置及命令行接口详解 3、实现kickstart文件制作与光盘镜像制作    

    2018-01-12
  • EXT4文件系统的初步使用

    文件系统的类型多种多样,我们接触得比较多的当属Windows系统上的FAT32和NTFS。 而EXT文件系统(Extended filesystem)则是linux上常见的文件系统类型。 目前最新的版本是ext4,常见于CentOS6之中。 1.查看当前系统中有没有挂载使用中的EXT4文件系统,可以使用mount命令: 2.如何创建一个EXT4的文件系统(f…

    系统运维 2016-02-14

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-13 23:21

    赞,看到内容就想多看一点,另外答案也很好哦。继续保持~