集中练习2

用户管理、文本处理、文件管理相关

(1) 复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限。
“`
~]# cp -r /etc/skel /home/tuser1
~]# touch /home/tuser1/{a,b,c}
~]# mkdir /home/tuser1/abc/db/dc -pv
~]# tree /home/tuser1
/home/tuser1
├── a
├── abc
│ └── db
│ └── dc
├── b
└── c
~]# ll /home/tuser1
total 0
-rw——-. 1 root root 0 Sep 19 19:13 a
drwx——. 3 root root 16 Sep 19 19:12 abc
-rw——-. 1 root root 0 Sep 19 19:13 b
-rw——-. 1 root root 0 Sep 19 19:13 c
~]# ls -ld /home/tuser1
drwx——. 4 root root 116 Sep 19 19:13 /home/tuser1
“`
(2) 编辑/etc/group文件,添加组hadoop。
“`
~]# vim /etc/group
在文件末尾添加一行:hadoop:x:1008:
~]# tail -1 /etc/group
hadoop:x:1008:
“`
(3) 手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
“`
~]# vim /etc/passwd
在文件末尾添加一行:hadoop:x:1008:1008::/home/hadoop:/bin/bash
~]# tail -1 /etc/passwd
hadoop:x:1008:1008::/home/hadoop:/bin/bash
“`
(4) 复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其他用户没有任何访问权限。
“`
~]# cp -r /etc/skel /home/hadoop
~]# chmod go-rwx /home/hadoop
~]# ls -ld /home/hadoop
drwx——. 3 root root 78 Sep 19 19:23 /home/hadoop
“`
(5) 修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
“`
~]# mkdir /home/hadoop/test
~]# touch /home/hadoop/test/{a,b,c,d}
~]# tree /home/hadoop
/home/hadoop
└── test
├── a
├── b
├── c
└── d
~]# chown -R hadoop:hadoop /home/hadoop
~]# ls -ld /home/hadoop
drwx——. 4 hadoop hadoop 90 Sep 19 19:28 /home/hadoop
~]# ll /home/hadoop/test/
total 0
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 a
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 b
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 c
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 d
“`
(6) 显示/proc/meminfo文件中以答谢或小写s开头的行;用两种方式。
“`
方法1:~]# grep -i “^s” /proc/meminfo
方法2:~]# grep -E “^(s|S)” /proc/meminfo
方法3:~]# grep “^[s,S]” /proc/meminfo
“`
(7) 显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户。
“`
~]# grep -v “/sbin/nologin$” /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
sapbcs
openstack
mariadb
gentoo
fedora
centos
tom
jerry
neo
hadoop
“`
(8) 显示/etc/passwd文件中其默认shell为/bin/bash的用户。
“`
~]# grep “/bin/bash$” /etc/passwd | cut -d: -f1
root
sapbcs
openstack
gentoo
fedora
centos
tom
jerry
neo
hadoop
“`
(9) 找出/etc/passwd文件中的一位数或两位数。
“`
~]# grep -E “\<[0-9]\>|\<[1-9][0-9]\>” /etc/passwd
“`
(10) 显示/boot/grub/grub.conf中至少一个空白字符开头的行。
“`
CentOS7没有题中的文件,我换了一个文件。
~]# grep -E “^[[:space:]]+” /boot/grub2/grub.cfg
“`
(11) 显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行。
“`
CentOS7中没有题中的文件,我换了一个文件
~]# grep -E “^#[[:space:]]+.*[^[:space:]]+” /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’,后或跟空白字符结尾的行。
“`
~]# netstat -tan | grep -E “LISTEN[[:space:]]+”
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
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 :::111 :::* 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相同的用户的信息。
“`
~]# useradd bash
~]# useradd testbash
~]# useradd basher
~]# useradd nologin -s /sbin/nologin
~]# grep -E “^(\<[[: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:1009:1009::/home/bash:/bin/bash
nologin:x:1012:1012::/home/nologin:/sbin/nologin
“`

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

(0)
N27_sapbcsN27_sapbcs
上一篇 2017-09-20 17:49
下一篇 2017-09-20 17:51

相关推荐

  • Nginx作为web服务器的使用配置

    概述     Nginx是一款免费开源的web服务器,同时也可以作为http、imap/pop3协议进行反代服务器,本篇介绍一些nginx作为web服务器方面的相关配置,具体包含:     1、nginx基础概念介绍     2、nginx…

    Linux干货 2016-10-27
  • CentOS 6.5下OpenVPN的搭建

    一、openvpn原理 二、安装openvpn 三、制作相关证书     3.1 制作CA证书     3.2 制作Server端证书     3.3 制作Client端证书 四、配置Server端 五、配置Client端 一、openvp…

    Linux干货 2016-04-21
  • vim编辑器

    vim编辑器:          文本:ASCII, Unicode(全球统一编码格式)          文本编辑种类:       &n…

    Linux干货 2016-08-10
  • linux 系统启动流程探讨

    linux系统启动流程: linux系统启动流程,按层次分的话,可以分为内核空间的启动与用户空间的启动。 下面先说说内核空间的启动流程。 一个linux要跑起来,在最简陋的情况下,必须有:kernel , lib ,application kernel功能:加载驱动程序,内存管理,进程管理,文件系统,网络管理,安全管理,glibc 库: 是一个函数的集合,每…

    Linux干货 2017-04-11
  • 马哥教育网络班21期+第4周课程练习

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 # cp -a /etc/skel /home/tuser1 # chmod -R g-rwx,o-rwx /home/tuser1/ 2、编辑…

    Linux干货 2016-07-16
  • 20170714上课LINUX入门

    1、安装centos6.9和centos7.3时的分区情况 /dev/sda1 mount /boot 1G – 主分区/dev/sda2 mount / 50G -主分区/dev/sda3 mount /app 40G -主分区/dev/sda4 1k 扩展分区/dev/sda5 swap 2G -逻辑分区(swap分区的大小一般为物理内存的2…

    Linux干货 2017-07-15