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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 221,548评论 6 515
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,497评论 3 399
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 167,990评论 0 360
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,618评论 1 296
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,618评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,246评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,819评论 3 421
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,725评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,268评论 1 320
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,356评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,488评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,181评论 5 350
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,862评论 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,331评论 0 24
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,445评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,897评论 3 376
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,500评论 2 359

推荐阅读更多精彩内容