1.复制/etc/skel目录为/home/tuser1,要求/home/tuser1 及其内部文件的属组和其他用户均没有任何访问权限.
完成命令:
cp -r /etc/skel /home/tuser1
chmod -R g=,o= /home/tuser1
示例:
[root@localhost ~]# cp -r /etc/skel /home/tuser1
[root@localhost ~]# ls -al /home/tuser1
总用量 12
drwxr-xr-x. 2 root root 62 3月 25 18:29 .
drwxr-xr-x. 9 root root 107 3月 25 18:29 ..
-rw-r--r--. 1 root root 18 3月 25 18:29 .bash_logout
-rw-r--r--. 1 root root 193 3月 25 18:29 .bash_profile
-rw-r--r--. 1 root root 231 3月 25 18:29 .bashrc
[root@localhost ~]# chmod -R g=,o= /home/tuser1
[root@localhost ~]# ls -al /home/tuser1
总用量 12
drwx------. 2 root root 62 3月 25 18:29 .
drwxr-xr-x. 9 root root 107 3月 25 18:29 ..
-rw-------. 1 root root 18 3月 25 18:29 .bash_logout
-rw-------. 1 root root 193 3月 25 18:29 .bash_profile
-rw-------. 1 root root 231 3月 25 18:29 .bashrc
2.编辑/etc/group文件,添加组hadoop。
完成命令:vim /etc/group
向文本末行添加 ''hadoop:x:1000''
示例:
[root@localhost ~]# vim /etc/group
mem:x:8:
10 kmem:x:9:
11 wheel:x:10:
12 cdrom:x:11:
13 mail:x:12:postfix
······
37 postfix:x:89:
38 sshd:x:74:
39 chrony:x:995:
40 hadoop:x:1000: 添加组名及组的ID号
:wq 输入wq,保存并退出!
[root@localhost ~]# tail -1 /etc/group 查看是否添加成功
hadoop:x:1000:
3.手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop
完成命令:vim /etc/passwd
向文本末行添加"hadoop:x:1000:1000::/home/hadoop:/bin/bash"
示例:
[root@localhost ~]# vim /etc/passwd
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
......
chrony:x:997:995::/var/lib/chrony:/sbin/nologin
hadoop:x:1000:1000::/home/hadoop:/bin/bash 添加用户名,用户和组ID号,家目录及默认shell路径
:wq 保存并退出!
[root@localhost ~]# tail -1 /etc/passwd
hadoop:x:1000:1000::/home/hadoop:/bin/bash
[root@localhost ~]# id hadoop
uid=1000(hadoop) gid=1000 组=1000 用户已成功创建
4.复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其他用用户没有任何访问权限。
完成命令:
cp -r /etc/skel /home/hadoop
chmod g=,o= /hom/hadoop
示例:
[root@localhost ~]# cp -r /etc/skel /home/hadoop
[root@localhost ~]# ls -ld /home/hadoop
drwxr-xr-x. 2 root root 62 3月 25 16:50 /home/hadoop
[root@localhost ~]# chmod g=,o= /home/hadoop
[root@localhost ~]# ls -ld /home/hadoop
drwx------. 2 root root 62 3月 25 16:50 /home/hadoop
5.修改home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
完成命令:chown -R hadoop:hadoop /home/hadoop
示例:
[root@localhost ~]# chown -R hadoop:hadoop /home/hadoop
[root@localhost ~]# ls -ld /home/hadoop
drwx------. 2 hadoop hadoop 62 3月 25 16:50 /home/hadoop
[root@localhost ~]# ls -al /home/hadoop
总用量 12
drwx------. 2 hadoop hadoop 62 3月 25 16:50 .
drwxr-xr-x. 4 root root 36 3月 25 16:50 ..
-rw-r--r--. 1 hadoop hadoop 18 3月 25 16:50 .bash_logout
-rw-r--r--. 1 hadoop hadoop 193 3月 25 16:50 .bash_profile
-rw-r--r--. 1 hadoop hadoop 231 3月 25 16:50 .bashrc
6.显示/proc/meminfo文件中以大写或小写s开头的行;用两种方式;
完成命令:
grep -i ^[s] /proc/meminfo
grep ^[S,s] /proc/meminfo
示例:
[root@localhost ~]# grep -i ^[s] /proc/meminfo
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 6896 kB
Slab: 80692 kB
SReclaimable: 43120 kB
SUnreclaim: 37572 kB
[root@localhost ~]# grep ^[S,s] /proc/meminfo
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 6896 kB
Slab: 80692 kB
SReclaimable: 43120 kB
SUnreclaim: 37572 kB
7.显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;
完成命令:
grep -v '/sbin/nologin' /etc/passwd | cut -d: -f1
示例:
[root@localhost ~]# grep -v '/sbin/nologin' /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
hadoop
8.显示/etc/passwd文件中其默认shell为/bin/bash的用户;
完成命令:
grep '/bin/bash' /etc/passwd | cut -d: -f1
示例:
[root@localhost ~]# grep '/bin/bash' /etc/passwd | cut -d: -f1
root
hadoop
9.找出/etc/passwd文件中的一位数或两位数;
完成命令:grep '<[0-9]{1,2}>' /etc/passwd
示例:
[root@localhost ~]# grep '\<[0-9]\{1,2\}\>' /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
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
10.显示/boot/grub2/grub.cfg中以至少一个空白字符开头的行;
完成命令:
grep '^[[:space:]]+' /boot/grub2/grub.cfg
示例:
[root@localhost ~]# grep '^[[:space:]]\+' /boot/grub2/grub.cfg
load_env
set default="${next_entry}"
set next_entry=
save_env next_entry
set boot_once=true
set default="${saved_entry}"
menuentry_id_option="--id"
menuentry_id_option=""
set saved_entry="${prev_saved_entry}"
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
if [ -z "${boot_once}" ]; then
saved_entry="${chosen}"
save_env saved_entry
fi
......
11.显示/etc/rc.d/rc.local文件中以#开头,后面跟上至少一个空白字符,而后又有至少一个非空白字符的行。
完成命令:
grep '^#[[:space:]] \ + [^[:space:]] \ + ' /etc/rc.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.
12.打出netstat -tan命令执行结果中以‘LISTEN',后或跟空白字符结尾的行;
完成命令:netstat -tan | grep 'LISTEN[[:space:]] * $'
示例:
[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
13.添加用户bash,testbash,basher,nologin(此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户信息;
完成命令:
useradd ‘username’
grep -E "^( [^:]+ \ >). * \1$" /etc/passwd
示例:
[root@localhost ~]# useradd bash
[root@localhost ~]# useradd testbash
[root@localhost ~]# useradd basher
[root@localhost ~]# useradd nologin
[root@localhost ~]# usermod -s /sbin/nologin nologin
[root@localhost ~]# tail -4 /etc/passwd
bash:x:1001:1001::/home/bash:/bin/bash
testbash:x:1002:1002::/home/testbash:/bin/bash
basher:x:1003:1003::/home/basher:/bin/bash
nologin:x:1004:1004::/home/nologin:/sbin/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:1001:1001::/home/bash:/bin/bash
nologin:x:1004:1004::/home/nologin:/sbin/nologin