(1) 復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其他用戶均沒有任何訪問權限。
“`
~]# cp -r /etc/skel /home/tuser1
~]# touch /home/tuser1/{a,b,c}
~]# mkdir /home/tuser1/abc/db/dc -pv
~]# tree /home/tuser1
/home/tuser1
├── a
├── abc
│ └── db
│ └── dc
├── b
└── c
~]# ll /home/tuser1
total 0
-rw——-. 1 root root 0 Sep 19 19:13 a
drwx——. 3 root root 16 Sep 19 19:12 abc
-rw——-. 1 root root 0 Sep 19 19:13 b
-rw——-. 1 root root 0 Sep 19 19:13 c
~]# ls -ld /home/tuser1
drwx——. 4 root root 116 Sep 19 19:13 /home/tuser1
“`
(2) 編輯/etc/group文件,添加組hadoop。
“`
~]# vim /etc/group
在文件末尾添加一行:hadoop:x:1008:
~]# tail -1 /etc/group
hadoop:x:1008:
“`
(3) 手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop。
“`
~]# vim /etc/passwd
在文件末尾添加一行:hadoop:x:1008:1008::/home/hadoop:/bin/bash
~]# tail -1 /etc/passwd
hadoop:x:1008:1008::/home/hadoop:/bin/bash
“`
(4) 復制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其他用戶沒有任何訪問權限。
“`
~]# cp -r /etc/skel /home/hadoop
~]# chmod go-rwx /home/hadoop
~]# ls -ld /home/hadoop
drwx——. 3 root root 78 Sep 19 19:23 /home/hadoop
“`
(5) 修改/home/hadoop目錄及其內部所有文件的屬主為hadoop,屬組為hadoop。
“`
~]# mkdir /home/hadoop/test
~]# touch /home/hadoop/test/{a,b,c,d}
~]# tree /home/hadoop
/home/hadoop
└── test
├── a
├── b
├── c
└── d
~]# chown -R hadoop:hadoop /home/hadoop
~]# ls -ld /home/hadoop
drwx——. 4 hadoop hadoop 90 Sep 19 19:28 /home/hadoop
~]# ll /home/hadoop/test/
total 0
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 a
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 b
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 c
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 d
“`
(6) 顯示/proc/meminfo文件中以答謝或小寫s開頭的行;用兩種方式。
“`
方法1:~]# grep -i “^s” /proc/meminfo
方法2:~]# grep -E “^(s|S)” /proc/meminfo
方法3:~]# grep “^[s,S]” /proc/meminfo
“`
(7) 顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶。
“`
~]# grep -v “/sbin/nologin$” /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
sapbcs
openstack
mariadb
gentoo
fedora
centos
tom
jerry
neo
hadoop
“`
(8) 顯示/etc/passwd文件中其默認shell為/bin/bash的用戶。
“`
~]# grep “/bin/bash$” /etc/passwd | cut -d: -f1
root
sapbcs
openstack
gentoo
fedora
centos
tom
jerry
neo
hadoop
“`
(9) 找出/etc/passwd文件中的一位數或兩位數。
“`
~]# grep -E “\<[0-9]\>|\<[1-9][0-9]\>” /etc/passwd
“`
(10) 顯示/boot/grub/grub.conf中至少一個空白字符開頭的行。
“`
CentOS7沒有題中的文件,我換了一個文件。
~]# grep -E “^[[:space:]]+” /boot/grub2/grub.cfg
“`
(11) 顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行。
“`
CentOS7中沒有題中的文件,我換了一個文件
~]# grep -E “^#[[:space:]]+.*[^[:space:]]+” /etc/rc.d/rc.local
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
# Please note that you must run ‘chmod +x /etc/rc.d/rc.local’ to ensure
# that this script will be executed during boot.
“`
(12) 打出netstat -tan命令執行結果中以’LISTEN’,后或跟空白字符結尾的行。
“`
~]# netstat -tan | grep -E “LISTEN[[:space:]]+”
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 192.168.122.1:53 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
tcp6 0 0 :::111 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
“`
(13) 添加用戶bash,testbash,basher,nologin(此一用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息。
“`
~]# useradd bash
~]# useradd testbash
~]# useradd basher
~]# useradd nologin -s /sbin/nologin
~]# grep -E “^(\<[[:alpha:]]+[^:]\>).*\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:1009:1009::/home/bash:/bin/bash
nologin:x:1012:1012::/home/nologin:/sbin/nologin
“`
本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/87470