1.复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。
[ root@localhost ~ ] # cp - r / etc/ skel / home/ tuser1
[ root@localhost ~ ] # ll / home/
drwxr- xr- x. 2 root root 62 Dec 11 06 : 48 tuser1
drwx-- -- -- . 2 user1 user1 62 Dec 9 21 : 25 user1
drwx-- -- -- . 2 user3 user3 62 Dec 9 22 : 27 user3
[ root@localhost ~ ] # chmod - R 700 / home/ tuser1
[ root@localhost ~ ] # ll / home/ | grep tuser1
drwx-- -- -- . 2 root root 62 Dec 11 06 : 48 tuser1
[ root@localhost ~ ] #
2.编辑/etc/group文件,添加组hadoop。
[ root@localhost ~ ] # cat / etc/ group | grep hadoop
hadoop: x: 2019 :
[ root@localhost ~ ] #
3.手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
[ root@localhost ~ ] # cat / etc/ passwd | grep hadoop
hadoop: x: 2019 : 2019 : : / home/ hadoop: / bin/ bash
[ root@localhost ~ ] #
4.复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。
[ root@localhost ~ ] # chmod - R 700 / home/ hadoop/
[ root@localhost ~ ] # ls - al / home/ hadoop
total 12
drwx-- -- -- . 2 root root 62 Dec 11 07 : 55 .
drwxr- xr- x. 20 root root 266 Dec 11 07 : 55 . .
- rwx-- -- -- . 1 root root 18 Dec 11 07 : 55 . bash_logout
- rwx-- -- -- . 1 root root 193 Dec 11 07 : 55 . bash_profile
- rwx-- -- -- . 1 root root 231 Dec 11 07 : 55 . bashrc
[ root@localhost ~ ] #
5.修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
[ root@localhost ~ ] # ll - d / home/ hadoop
drwx-- -- -- . 2 root root 62 Dec 11 07 : 55 / home/ hadoop
[ root@localhost ~ ] # chown - R hadoop: hadoop / home/ hadoop
[ root@localhost ~ ] # ll - d / home/ hadoop
drwx-- -- -- . 2 hadoop hadoop 62 Dec 11 07 : 55 / home/ hadoop
[ root@localhost ~ ] #
6.显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;
[ root@localhost ~ ] # cat / proc/ meminfo | grep - i "^s"
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 9668 kB
Slab: 62284 kB
SReclaimable: 26632 kB
SUnreclaim: 35652 kB
[ root@localhost ~ ] # grep "^[sS]" / proc/ meminfo
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 9668 kB
Slab: 62284 kB
SReclaimable: 26632 kB
SUnreclaim: 35652 kB
7.显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;
[ root@localhost ~ ] # grep "/sbin/nologin" / etc/ passwd
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
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
systemd- network: x: 192 : 192 : systemd Network Management: / : / sbin/ nologin
dbus: x: 81 : 81 : System message bus: / : / sbin/ nologin
polkitd: x: 999 : 998 : User for polkitd: / : / sbin/ nologin
sshd: x: 74 : 74 : Privilege- separated SSH: / var/ empty/ sshd: / sbin/ nologin
postfix: x: 89 : 89 : : / var/ spool/ postfix: / 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
luokun: x: 1000 : 1000 : luokun: / home/ luokun: / bin/ bash
tcwy_lk: x: 1001 : 1001 : : / home/ tcwy_lk: / bin/ bash
centos: x: 1002 : 1002 : : / home/ centos: / bin/ bash
cloudstack: x: 1006 : 1005 : : / home/ cloudstack: / bin/ bash
gentoo: x: 4001 : 4001 : : / home/ gentoo: / bin/ bash
fedora: x: 4002 : 4002 : Fedora Core: / home/ fedora: / bin/ tcsh
docker: x: 4003 : 4003 : Docker, white house, 911 , 110 : / home/ docker: / bin/ bash
mageia: x: 1100 : 1100 : : / home/ linux: / bin/ bash
slackware: x: 2002 : 2016 : : / home/ slackware: / bin/ tcsh
user1: x: 4004 : 4006 : : / home/ user1: / bin/ bash
user3: x: 4005 : 4007 : : / home/ user3: / bin/ bash
hadoop: x: 2019 : 2019 : : / home/ hadoop: / bin/ bash
[ root@localhost ~ ] # grep - v "/sbin/nologin" / etc/ passwd | cut - d: - f1
root
sync
shutdown
halt
luokun
tcwy_lk
centos
cloudstack
gentoo
fedora
docker
mageia
slackware
user1
user3
hadoop
[ root@localhost ~ ]
8.显示/etc/passwd文件中其默认shell为/bin/bash的用户;
[ root@localhost ~ ] # grep "/bin/bash" / etc/ passwd | cut - d: - f1
root
luokun
tcwy_lk
centos
cloudstack
gentoo
docker
mageia
user1
user3
9.找出/etc/passwd文件中的一位数或两位数;
[ root@localhost ~ ] # grep "\<[0-9][0-9]\?\>" / 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
sshd: x: 74 : 74 : Privilege- separated SSH: / var/ empty/ sshd: / sbin/ nologin
postfix: x: 89 : 89 : : / var/ spool/ postfix: / sbin/ nologin
[ root@localhost ~ ] #
10.显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
[ root@localhost ~ ] # grep "^[[:space:]]\+" / boot/ grub/ grub. conf
grep: / boot/ grub/ grub. conf: No such file or directory
[ root@localhost ~ ] # ls / boot/ grub
grub/ grub2/
[ root@localhost ~ ] # ls / boot/ grub/
splash. xpm. gz
11.显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
[ root@localhost ~ ] # ls / etc/ rc. d/
init. d rc0. d rc1. d rc2. d rc3. d rc4. d rc5. d rc6. d rc. local
[ root@localhost ~ ] # grep "^#[[: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.
[ root@localhost ~ ] #
12.打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;
[ root@localhost ~ ] # netstat - tan | grep " LISTEN[[:space:]]*$"
tcp 0 0 0.0 .0 .0 : 22 0.0 .0 .0 : * LISTEN
tcp 0 0 127.0 .0 .1 : 25 0.0 .0 .0 : * LISTEN
tcp6 0 0 : : : 22 : : : * LISTEN
tcp6 0 0 : : 1 : 25 : : : * LISTEN
[ root@localhost ~ ] #
13.添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;
[ root@localhost ~ ] # useradd bash
[ root@localhost ~ ] # useradd testbash
[ root@localhost ~ ] # useradd basher
[ root@localhost ~ ] # useradd - s / sbin/ nologin nologin
[ root@localhost ~ ] # grep - E "^([^:]+\>).*\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: 4006 : 4008 : : / home/ bash: / bin/ bash
nologin: x: 4009 : 4011 : : / home/ nologin: / sbin/ nologin
[ root@localhost ~ ] #