首页 > 代码库 > 第四周作业

第四周作业

注意:第四周作业,请将以下题目整理在51cto博客当中,完成后请将对应的博文链接地址提交在答案栏中,提交格式如下:

学号+姓名+博文链接地址

eg1+张三+httpmageedu.blog.51cto.com42656101794420

 

本周作业内容:

1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。

   #cp /etc/skel  /home/tuser1   

   #chmod  -r 700 /home/ruser1

2、编辑/etc/group文件,添加组hadoop

  #vi + /etc/group

   冒号模式下:?hadoop   结果显示没有该组

    直接键入输入hadoop:x:503:

     wq 退出

3、手动编辑/etc/passw d文件新增一行,添加用户hadoop,其基本组IDhadoop组的id号;其家目录为/home/hadoop

vim /etc/passwd: 进入命令行模式,输入$ 让光标处于最后一行

进入编辑模式输入

之后截图

apache:x:48:48:Apache:/var/www:/sbin/nologin

saslauth:x:498:76:Saslauthduser:/var/empty/saslauth:/sbin/nologin

postfix:x:89:89::/var/spool/postfix:/sbin/nologin

gdm:x:42:42::/var/lib/gdm:/sbin/nologin

pulse:x:497:496:PulseAudioSystem Daemon:/var/run/pulse:/sbin/nologin

sshd:x:74:74:Privilege-separatedSSH:/var/empty/sshd:/sbin/nologin

tcpdump:x:72:72::/:/sbin/nologin

sanjiang:x:500:500:zhusanjiang:/home/sanjiang:/bin/bash

456:x:501:501::/home/456:/etc/123

gentoo:x:502:502:gentoodistribution:/home/gentoo:/bin/bash

hadoop:x:503:503:hadoop:/home/hadoop:/bin/bash

 

"/etc/passwd"42L, 1948C

下一步             

[root@localhost~]# cat /etc/passwd | grep ^hadoop

hadoop:x:503:503:hadoop:/home/hadoop:/bin/bash

[root@localhost~]#

 

 

 

4、复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。

第一步截取

 [root@localhost~]#

[root@localhost ~]# cp -r /etc/skel//home/hadoop

[root@localhost ~]# ls -a /home/hadoop/

. ..  .bash_logout  .bash_profile .bashrc  .gnome2  .mozilla skel

[root@localhost ~]#

第二步截取

[root@localhost ~]# ls -ld /home/hadoop/

drwxr--r--. 5 hadoop hadoop 4096 10 15 08:45/home/hadoop/

[root@localhost ~]# chmod go=-/home/hadoop/

[root@localhost ~]# ls -ld /home/hadoop/

drwx------. 5 hadoop hadoop 4096 10 15 08:45/home/hadoop/

[root@localhost ~]#

 

 

5、修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop

完成之后截取

[root@localhost ~]# chown –R hadoop:hadoop/home/hadoop

[root@localhost~]#  ls –al  /home/hadoop

总用量 32

drwx------. 5 hadoop hadoop 4096 10 15 08:45 .

drwxr-xr-x. 11 root   root  4096 10 14 00:08 ..

-rw-r--r--. 1 hadoop hadoop   18 10 13 22:51.bash_logout

-rw-r--r--. 1 hadoop hadoop  176 10 13 22:51.bash_profile

-rw-r--r--. 1 hadoop hadoop  124 10 13 22:51.bashrc

drwxr-xr-x. 2 hadoop hadoop 4096 10 13 22:51 .gnome2

drwxr-xr-x. 4 hadoop hadoop 4096 10 13 22:51 .mozilla

drwxr-xr-x. 4 root   root   4096 10 15 08:45 skel

 

6、显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;

方法1

[root@localhost ~]# grep -i ^s/proc/meminfo

SwapCached:            0 kB

SwapTotal:       2031612 kB

SwapFree:        2031612 kB

Shmem:              5588 kB

Slab:             116196 kB

SReclaimable:      44880 kB

SUnreclaim:        71316 kB

方法2

[root@localhost ~]# grep -i ^[Ss]/proc/meminfo

SwapCached:            0 kB

SwapTotal:       2031612 kB

SwapFree:        2031612 kB

Shmem:              5588 kB

Slab:             116212 kB

SReclaimable:      44888 kB

SUnreclaim:        71324 kB

7、显示/etc/passw d文件中其默认shell为非/sbin/nologin的用户;

完成之后截屏

[root@localhost ~]# grep -v"/sbin/nologin$" /etc/passwd

root:x:0:0:root:/root:/bin/bash

sync:x:5:0:sync:/sbin:/bin/sync

shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

halt:x:7:0:halt:/sbin:/sbin/halt

sanjiang:x:500:500:zhusanjiang:/home/sanjiang:/bin/bash

456:x:501:501::/home/456:/etc/123

gentoo:x:502:502:gentoo distribution:/home/gentoo:/bin/bash

hadoop:x:503:503:hadoop:/home/hadoop:/bin/bash

 

basher:x:506:508::/home/basher:/etc/bash

nologin:x:507:509::/home/nologin:/etc/bash

[root@localhost ~]# grep -v"/sbin/nologin$" /etc/passwd | cut -d: -f 1

root

sync

shutdown

halt

sanjiang

456

gentoo

hadoop

 

basher

nologin

 

8、显示/etc/passw d文件中其默认shell/bin/bash的用户;

完成之后截取

[root@localhost ~]# grep  "/bin/bash$" /etc/passwd | cut -d:-f 1

root

sanjiang

gentoo

hadoop

9、找出/etc/passw d文件中的一位数或两位数;

完成之后截取

[root@localhost ~]# grep -o"[[:digit:]]\{0,\}" /etc/passwd

0

0

1

1

2

2

3

4

4

7

5

0

6

0

7

0

8

12

 

10、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;

完成之后截取

[root@localhost ~]# grep"^[[:space:]]\+" /boot/grub/grub.conf

         root(hd0,0)

         kernel/vmlinuz-3.10.103123 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS rd_NO_MDrd_LVM_LV=VolGroup/lv_swap crashkernel=auto.UTF-8rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pcKEYTABLE=us rd_NO_DM rhgb quiet

         initrd/initramfs-3.10.103123.img

         root(hd0,0)

         kernel/vmlinuz-3.10.103zhusanjiang ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKSrd_NO_MD rd_LVM_LV=VolGroup/lv_swap crashkernel=auto.UTF-8 rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgbquiet

         initrd/initramfs-3.10.103zhusanjiang.img

         root(hd0,0)

         kernel/vmlinuz-2.6.32-642.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKSrd_NO_MD rd_LVM_LV=VolGroup/lv_swap crashkernel=auto.UTF-8rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet

         initrd/initramfs-2.6.32-642.el6.x86_64.img

 

11、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行

完成之后截取

[root@localhost ~]# grep"^#[[:space:]]\+[^[:space:]]\+" /etc/rc.d/rc.sysinit

# /etc/rc.d/rc.sysinit - run once at boottime

# Taken in part from Miquel vanSmoorenburg‘s bcheckrc.

# Check SELinux status

# Print a text banner.

# Only read this once.

# Initialize hardware

# Set default affinity

# Load other user-defined modules

# Load modules (for backward compatibilitywith VARs)

# Configure kernel parameters

# Set the hostname.

# Sync waiting for storage.

# Device mapper & related initializa

12、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;

完成之后截取

[root@localhost ~]# netstat -tan | grep"LISTEN[[:space:]]\{0,\}$"

tcp       0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN     

tcp       0      0 0.0.0.0:39093               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 :::35332                    :::*                        LISTEN     

tcp       0      0 :::111                      :::*                        LISTEN     

tcp       0      0 :::22                       :::*                        LISTEN     

tcp       0      0 ::1:631                     :::*                        LISTEN     

tcp       0      0 ::1:25                      :::*                        LISTEN     

tcp       0      0 ::1:6010                    :::*                        LISTEN     

 

13、添加用户bash, testbash, basher, nologin (此一个用户的shell/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;

useradd   bash

useradd -s /sbin/nologin testbash

useradd   basher

useradd nologin

[root@localhost ~]# tail -4 /etc/passwd

bash:x:504:506::/home/bash:/sbin/nologin

testbash:x:505:507::/home/testbash:/sbin/nologin

basher:x:506:508::/home/basher:/etc/bash

nologin:x:507:509::/home/nologin:/etc/bash

最后一步

 

 

[root@localhost ~]# 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


第四周作业