Linux第四周作业

Linux

1、 复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。
~]# cp /etc/skel/ /home/tuser1
home]# getfacl tuser1/
# file: tuser1/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
home]# setfacl -m u::7,g::0,o::0 tuser1/
[root@ada-dog home]# getfacl tuser1/
# file: tuser1/
# owner: root
# group: root
user::rwx
group::—
other::—

2、 编辑/etc/group文件,添加组hadoop。
~]# echo “hadoop:x:1004:” >> /etc/group
3、 手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
~]# echo “hadoop:x:1003:1004::/home/hadoop:/bin/bash” >> /etc/passwd
4、 复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。
home]# cp -rv /etc/skel/ /home/hadoop/
“/etc/skel/” -> “/home/hadoop/”
“/etc/skel/.mozilla” -> “/home/hadoop/.mozilla”
“/etc/skel/.mozilla/extensions” -> “/home/hadoop/.mozilla/extensions”
“/etc/skel/.mozilla/plugins” -> “/home/hadoop/.mozilla/plugins”
“/etc/skel/.bash_logout” -> “/home/hadoop/.bash_logout”
“/etc/skel/.bash_profile” -> “/home/hadoop/.bash_profile”
“/etc/skel/.bashrc” -> “/home/hadoop/.bashrc”
[root@ada-dog home]# getfacl hadoop/
# file: hadoop/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
home]# setfacl -m u::7,g::0,o::0 hadoop/
[root@ada-dog home]# getfacl hadoop/
# file: hadoop/
# owner: root
# group: root
user::rwx
group::—
other::—

5、 修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
home]# chown -Rv hadoop:hadoop /home/hadoop/
changed ownership of “/home/hadoop/.mozilla/extensions” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.mozilla/plugins” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.mozilla” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.bash_logout” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.bash_profile” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.bashrc” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/” from root:root to hadoop:hadoop
home]# ls -al /home/hadoop/
总用量 12
drwx——. 3 hadoop hadoop 78 7月 10 15:41 .
drwxr-xr-x. 7 root root 73 7月 10 15:41 ..
-rw-r–r–. 1 hadoop hadoop 18 7月 10 15:41 .bash_logout
-rw-r–r–. 1 hadoop hadoop 193 7月 10 15:41 .bash_profile
-rw-r–r–. 1 hadoop hadoop 231 7月 10 15:41 .bashrc
drwxr-xr-x. 4 hadoop hadoop 39 7月 10 15:41 .mozilla
6、 显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;
~]# grep -i ‘^s’ /proc/meminfo
SwapCached: 1456 kB
SwapTotal: 3145724 kB
SwapFree: 3112296 kB
Shmem: 2252 kB
Slab: 57744 kB
SReclaimable: 19724 kB
SUnreclaim: 38020 kB
~]# grep -E ‘^[sS]’ /proc/meminfo
SwapCached: 1652 kB
SwapTotal: 3145724 kB
SwapFree: 3111748 kB
Shmem: 2216 kB
Slab: 57168 kB
SReclaimable: 19724 kB
SUnreclaim: 37444 kB

7、 显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;
~]# cat /etc/passwd | grep -v “/sbin/nologin” | cut -d: -f1
root
sync
shutdown
halt
ada
fedora
centos
hadoop
8、 显示/etc/passwd文件中其默认shell为/bin/bash的用户;
~]# cat /etc/passwd | grep “/bin/bash” | cut -d: -f1
root
ada
fedora
centos
hadoop

9、 找出/etc/passwd文件中的一位数或两位数;
~]# grep “\<[[:digit:]]\{,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
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
10、 显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
~]# grep “^[[:space:]]\+” /boot/grub/grub.conf
dfsgs
safa
gsgsg
wsd
sdfdse444
esg
fsgr\
11、 显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
~]# grep “^#[[:space:]]\+[^[:space:]]\+” /etc/rc.d/rc.sysinit
# It receives polydir path as $1, the instance path as $2,
# a flag whether the instance dir was newly created (0 – no, 1 – yes) in $3,
# and user name in $4.
# The following section will copy the contents of /etc/skel if this is a
# newly created home directory.

12、 打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;
~]# netstat -tan | grep “LISTEN[[:space:]]\+”
tcp 0 0 0.0.0.0:111 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
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:6011 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
tcp6 0 0 ::1:6010 :::* LISTEN
tcp6 0 0 ::1:6011 :::* LISTEN

13、 添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;
~]# useradd bash
~]# useradd testbash
~]# useradd basher
~]# useradd -s /sbin/nologin nologin
~]# 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:501:501::/home/bash:/bin/bash
nologin:x:504:504::/home/nologin:/sbin/nologin

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

(0)
上一篇 2018-07-14 16:28
下一篇 2018-07-14 19:26

相关推荐

  • 网线直连线与交叉线之间的区别

    UTP 直通线和交叉线

    Linux笔记 2018-05-05
  • at & crontab命令

    at命令 功能 at命令用于执行未来某个时间点的某一次任务,任务的执行结果为以邮件的形式发送给用户 命令格式 at [OPTION] TIME 常用选项[OPTION] -l 查看等待运行的任务 atq 命令也可用户查看等待运行的任务 -f /path/from/file 从指定文件中读取作业任务,而不再交互式输入 -d # 删除指定的作业任务 -c 查看指…

    Linux笔记 2018-06-11
  • linux中PAM的配置和使用

    linux中PAM的配置和使用方法

    Linux笔记 2018-05-24
  • 在CentOS 7.3中创建本地yum源

    1.挂载系统光盘 1.1创建挂载文件 [root@centos7 ~]# mkdir /mnt/cdrom                          #创建文件 1.2挂载光驱 [root@centos7 ~]# mount /dev/cdrom /mnt/cdrom/              #挂载光驱  mount: /dev/sr0 is w…

    Linux笔记 2017-05-18
  • linux 文本处理三剑客

    grep 作用:文本搜索工具,根据用户指定的“模式”对目标文本逐行进行匹配检查;打印匹配到的行。 模式:由正则表达式字符及文本符所编写的过滤条件 grep  命令选项: 正则表达式: 基本正则表达式元字符      字符匹配: 正则表达式: 正则表达式: 正则表达式: 示例:a\|b: a或b    C\|cat :C或cat         \(C\|c\…

    Linux笔记 2018-04-15
  • 第一周作业笔记

    1、描述计算机的组成及其功能。
    2、按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别。
    3、描述Linux的哲学思想,并按照自己的理解对其进行解释性描述。
    4、说明Linux系统上命令的使用格式;详细介绍ifconfig、echo、tty、startx、export、pwd、history、shutdown、poweroff、reboot、hwclock、date命令的使用,并配合相应的示例来阐述。
    5、如何在Linux系统上获取命令的帮助信息,请详细列出,并描述man文档的章节是如何划分的。
    6、请罗列Linux发行版的基础目录名称命名法则及功用规定

    Linux笔记 2018-06-21