N32-第四周-小罗

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

[root@host ~]# cp -r /etc/skel /home/tuser1
 --------------------------------------------------------
 [root@host ~]# ll /home/
total 60
drwx------ 2 bash      bash     4096 Jul  6 04:29 bash
drwx------ 2 basher    basher   4096 Jul  6 04:29 basher
drwx------ 2 centos    centos   4096 Jul 11 03:39 centos
drwx------ 2 centos10  centos10 4096 Jul 22 04:56 centos10
drwx------ 2 centos2   centos2  4096 Jul  4 04:29 centos2
drwx------ 2 centos3   centos3  4096 Jul  3 21:59 centos3
drwx------ 2 fedora    fedora   4096 Jul 11 02:51 fedora
drwx------ 2 hadoop    hadoop   4096 Jul  9 07:54 hadoop
drwx------ 2 mageia    mageia   4096 Jul  4 23:23 linux
drwx------ 2 distro   4096 Jul  4 23:01 mandriva
drwx------ 2 mygrp     mygrp    4096 Jul  9 08:29 mygrp
drwx------ 2 nologin   nologin  4096 Jul  6 04:30 nologin
drwx------ 2 slackware distro   4096 Sep  2 03:56 slackware
drwx------ 2 testbash  testbash 4096 Jul  6 04:29 testbash
drwxr-xr-x 2 root      root     4096 Sep  6 01:12 tuser1
--------------------------------------------------------
[root@host home]# chmod -R 700 tuser1/
[root@host home]# ll
drwx------ 2 root      root     4096 Sep  6 01:12 tuser1

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

[root@host home]# vim /etc/group  
按o键进入编辑模式,输入 :hadoop:x:2019
按esc键进入命令模式,按shift+:进入末行模式输入
:wq 回车键保存退出
--------------------------------------------------------
[root@host home]# grep hadoop /etc/group
hadoop:x:2019

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

[root@host home]# vim /etc/passwd
按o键进入编辑模式,输入hadoop:x:2019:2019::/home/hadoop:/bin/bash
按esc键进入命令模式,按shift+:进入末行模式输入
:wq 回车键保存退出
--------------------------------------------------------
[root@host home]# grep hadoop /etc/passwd
hadoop:x:2019:2019::/home/hadoop:/bin/bash

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

[root@host ~]# cp -rv /etc/skel /home/hadoop
`/etc/skel' -> `/home/hadoop'
`/etc/skel/.bash_logout' -> `/home/hadoop/.bash_logout'
`/etc/skel/.bashrc' -> `/home/hadoop/.bashrc'
`/etc/skel/.bash_profile' -> `/home/hadoop/.bash_profile'
--------------------------------------------------------
[root@host ~]# chmod -R 700 /home/hadoop
--------------------------------------------------------
[root@host ~]# ll -d /home/hadoop
drwx------ 2 root root 4096 Sep  6 02:33 /home/hadoop

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

[root@host ~]# chown -R hadoop:hadoop /home/hadoop
--------------------------------------------------------
[root@host ~]# ll -d /home/hadoop
drwx------ 2 hadoop hadoop 4096 Sep  6 02:33 /home/hadoop

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

[root@host ~]# cat /proc/meminfo | grep -i "^s"
SwapCached:          284 kB
SwapTotal:        135164 kB
SwapFree:         131708 kB
Shmem:                12 kB
Slab:              77836 kB
SReclaimable:      64888 kB
SUnreclaim:        12948 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
--------------------------------------------------------
[root@host ~]# cat /proc/meminfo | grep  "^\(s\|S\)"
SwapCached:          284 kB
SwapTotal:        135164 kB
SwapFree:         131708 kB
Shmem:                12 kB
Slab:              77836 kB
SReclaimable:      64888 kB
SUnreclaim:        12948 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB

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

[root@host ~]# cat /etc/passwd | grep -v "/sbin/nologin$" | cut -d: -f1
root
sync
shutdown
halt
centos2
centos3
mageia
slackware
bash
testbash
basher
centos
mygrp
fedora
centos10
archlinux
hadoop

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

[root@host ~]# cat /etc/passwd | grep "/bin/bash$"
root:x:0:0:root:/root:/bin/bash
centos2:x:501:501::/home/centos2:/bin/bash
centos3:x:502:502::/home/centos3:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016:/bin/tcsh:/home/slackware:/bin/bash
bash:x:2004:2004::/home/bash:/bin/bash
testbash:x:2005:2005::/home/testbash:/bin/bash
basher:x:2006:2006::/home/basher:/bin/bash
centos:x:2008:2008::/home/centos:/bin/bash
mygrp:x:2009:2009::/home/mygrp:/bin/bash
fedora:x:2010:2010::/home/fedora:/bin/bash
centos10:x:2011:2011::/home/centos10:/bin/bash
archlinux:x:2012:2012::/users/archlinux:/bin/bash
hadoop:x:2019:2019::/home/hadoop:/bin/bash

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

[root@host ~]# cat /etc/passwd | grep "[[:digit:]]\{0,1\}"
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
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin

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

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

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

[root@host ~]# cat /etc/rc.d/rc.sysinit | grep "^#[[:space:]]\+[^[:space:]]\+"
# /etc/rc.d/rc.sysinit - run once at boot time
# Taken in part from Miquel van Smoorenburg'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 compatibility with VARs)
# Configure kernel parameters
# Set the hostname.
# Sync waiting for storage.
# Device mapper & related initialization
# Start any MD RAID arrays that haven't been started yet
# Remount the root filesystem read-write.
# Clean up SELinux labels
# If relabeling, relabel mount points.
# Mount all other filesystems (except for NFS and /proc, which is already
# mounted). Contrary to standard usage,
# filesystems are NOT unmounted in single user mode.
# The 'no' applies to all listed filesystem types. See mount(8).
# Check to see if a full relabel is needed
# Update quotas if necessary
# Initialize pseudo-random number generator
# Configure machine if necessary.
# Clean out /.
# Do we need (w|u)tmpx files? We don't set them up, but the sysadmin might...
# Clean up /var.
# Clean up utmp/wtmp
# Clean up various /tmp bits
# Make ICE directory
# Start up swapping.
# Set up binfmt_misc
# Boot time profiles. Yes, this should be somewhere else.
# Now that we have all of our basic modules loaded and the kernel going,
# let's dump the syslog ring somewhere so we can find it later
# create the crash indicator flag to warn on crashes, offer fsck with timeout
# Let rhgb know that we're leaving rc.sysinit

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

[root@host ~]# netstat -tan | grep "LISTEN[[:space:]]\+$"
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:26605               0.0.0.0:*                   LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN      
tcp        0      0 :::443                      :::*                        LISTEN      
tcp        0      0 :::26605                    :::*                        LISTEN      

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

[root@host ~]# useradd bash
[root@host ~]# useradd testbash
[root@host ~]# useradd basher
[root@host ~]# useradd -s /sbin/nologin nologin
 --------------------------------------------------------
[root@host ~]# cat /etc/passwd | grep "^\([[:alnum:]]\+\).*\1$"
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
nobody:x:99:99:Nobody:/:/sbin/nologin
hadoop:x:2019:2019::/home/hadoop:/bin/bash
bash:x:2020:2020::/home/bash:/bin/bash
basher:x:2022:2022::/home/basher:/bin/bash
nologin:x:2023:2023::/home/nologin:/sbin/nologin

原创文章,作者:rocketsman,如若转载,请注明出处:http://www.178linux.com/123835

评论列表(1条)

  • 马哥教育
    马哥教育 2018-09-13 10:25

    写的很好,排版很漂亮,如果每个题目可以用多种方式来解答会更好

联系我们

400-080-6560

在线咨询

工作时间:周一至周五,9:30-18:30,节假日同时也值班

QR code