集中练习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

相关推荐

  • linux命令查找locate find要点

           在文件系统上查找符合的文件        locate, find locate:          依赖于事先构建好的索引库:             &…

    Linux干货 2016-11-07
  • cp,chmod,chown,chgrg,grep命令应用实例和总结

    1.复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的其他属组和其他用户没有任何访问权限。[root@dxlcentOS ~]# cp -a /etc/skel/ /home/tuser1[root@dxlcentOS ~]# chmod -R go= /home/tuser1 递归修改权限,g:组的权限,o其他…

    Linux干货 2017-10-26
  • nginx及I/O介绍原理

    上课笔记

    2018-03-12
  • MYSQL数据库基础教程

    一、数据库介绍 1.数据库管理系统的产生背景 (1)数据时代的到来要求对数据进行有效和安全的管理 涉及的数据量大 数据不随程序的结束而消失 数据被多个应用程序共享 大数据时代的到来 (2)传统文件系统管理上的缺陷要求改变数据管理方式 编写应用程序不方便 数据冗余不可避免 应用程序依赖性 不支持对文件的并发访问 数据间联系弱 难以按用户视图表示数据 无安全控制…

    Linux干货 2017-10-05
  • N25第九周作业

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash declare -a usersh nologin=0 login=0 usersh=($(cut -d’:’ -f7 /etc/passwd)) ##数组赋值时需…

    Linux干货 2017-03-04
  • jenkins+gitlab构建安卓自动编译环境

        因工作关系接触到接触到安卓自动编译环境,网上的资料都推荐了jenkins,因为第一次接触安卓和jenkins,踩了不少的坑,有总结才有进步。    gitlab环境之前已经安装完成可用,具体步骤另外详解吧。本例目标是在gitlab可用前提下,通过jenkins将git仓库的代码自行编译打包,生成可用的apk安装…

    Linux干货 2016-07-16