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)
FelixFelix
上一篇 2018-07-14 16:28
下一篇 2018-07-14 19:26

相关推荐

  • Linux笔记第一周

    一、描述计算机的组成及其功能。 计算机由硬件和软件两部分组成 硬件由主机与外部设备构成 软件由系统软件与应用软件构成 二、按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别。 Red Hat公司发布         Redhat Centos Novell公司发布             SUSE Debian维护社区发布   Debian ub…

    Linux笔记 2018-06-24
  • 第四周作业

    第四周作业
    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。
    2、编辑/etc/group文件,添加组hadoop。
    3、手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
    4、复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。
    5、修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
    6、显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;
    7、显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;
    8、显示/etc/passwd文件中其默认shell为/bin/bash的用户;
    9、找出/etc/passwd文件中的一位数或两位数;
    10、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
    11、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
    12、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;
    13、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;

    2018-06-07
  • sell 进阶

    删除shell函数:命令格式:unsrt function_name 创建函数:例 function func2 { echo fun2;}   fork  炸弹;:(){ :|&};: 脚本: cat  Bomb.sh #!/bin/bash ./$0./$0& 信号捕捉 trap ‘ehcho trap 15&#82…

    2018-05-10
  • shell脚本编程基础——循环用法

    本节索引: 一、if、case条件判断 二、for、while及until循环 三、循环控制语句continue、break、shift及select菜单 四、信号捕捉trap   在前面的基础编程内容中,我们已经学习了shell脚本的顺序执行及选择执行,通过这两种方式,可 以帮我们解决一些简单需求,但要想在更复杂的场景中使用的话,就需要掌握循环执…

    2018-05-10
  • Docker容器二

    容器的虚拟化网络;

    2018-08-01
  • 粗谈用户和用户组相关配置文件

    创建一个用户时,用户会根据系统配置文件来创建用户。配置文件在/etc/login.defs文件里 login.defs //创建账户自动分配参数 PASS_MAX_DAYS //可以使用密码的最大天数。 PASS_MIN_DAYS //密码更改之间允许的最短天数 PASS_MIN_LEN //最小可接受的密码长度 PASS_WARN_AGE //密码过期前发…

    Linux笔记 2018-04-08