集中练习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基础学习之进程管理和任务计划

    内容:   进程相关概念(用户空间、内核空间,进程、线程)   进程及系统相关工具(ps、top、pgrep、pidof、kill)   调整nice值(nice、renice)   作业管理(jobs、fg、bg、kill,&)   计划任务(at、crontab) 一、进程相关概念 内核的功用:进…

    Linux干货 2016-09-07
  • Windows 10 VS. Linux

    原文出处: Linux中国 – zpl1025   前阵子 Windows 10 好像占据了绝大部分头条,甚至在一些Linux圈里也是一样。最具代表性的是 betanews.com 的 Brian Fagioli 说 Windows 10 已经为 Linux 桌面系统敲响了丧钟,Microsoft 如今宣布将为忠实的…

    系统运维 2015-03-24
  • Linux基础命令及获取命令帮助

    何为命令?         linux命令是对Linux系统进行管理的命令。对于Linux系统来说,无论是中央处理器、内存、磁盘驱动器、键盘、鼠标,还是用户等都是文件,Linux系统管理的命令是它正常运行的核心,与之前的DOS命令类似。linux命令在系统中有两种类型:内置She…

    Linux干货 2016-10-25
  • CentOS7 Local yum的一次报错信息

    说明:今天在火车上测试一个CentOS7下的一个服务,要用到yum配置,但是本机没有联网,所以考虑到配置本地yum,按照之前CentOS6下的常规方法,居然发现有报错。 操作如下: 1)虚拟机下将CentOS7光盘加载到系统里面,然后挂载到本地的/localyum上 [root@localhost yum.repos.d]# mount&…

    Linux干货 2016-07-16
  • 编译安装http

    下载源码并解包   2 准备编译环境yum groupinstall “Development Tools” 3 编译安装   ./configure –prefix=/app/httpd24 –sysconfdir=/etc/httpd24/ –enable-ssl &#821…

    2017-12-02