1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。
[root@mageedu home]# cp -r /etc/skel/ /home/tuser1
[root@mageedu home]# chmod -R u-r,o-r tuser1/
[root@mageedu home]# ll
total 40
drwx------. 2 bash bash 4096 Aug 13 12:01 bash
drwx------. 2 basher basher 4096 Aug 13 12:01 basher
drwx------. 2 mageia mageia 4096 Aug 14 01:14 linux
drwx------. 2 1005 distro 4096 Aug 14 01:12 mandriva
drwx------. 2 nologin nologin 4096 Aug 13 12:01 nologin
drwx------. 2 openstack clouds 4096 Aug 14 01:50 openstack
drwx------. 2 slackware distro 4096 Aug 14 01:24 slackware
drwx------. 2 testbash testbash 4096 Aug 13 12:01 testbash
d-wxr-x--x. 2 root root 4096 Aug 14 13:58 tuser1
drwx------. 2 zengzy zengzy 4096 Aug 13 08:28 zengzy
[root@mageedu home]# su zengzy
[zengzy@mageedu home]$ cd /home/tuser1/
[zengzy@mageedu tuser1]$ ls
ls: cannot open directory .: Permission denied
2、编辑/etc/group文件,添加组hadoop。
[root@mageedu home]# vim /etc/group
root@mageedu home]# tail -n 5 /etc/group
admins:x:2018:slackware
clouds:x:2019:
nova:x:2020:openstack
mysql:x:498:
hadoop:x:499:
[root@mageedu home]# echo 'hadoop1:x:505:' >> /etc/group
[root@mageedu home]# tail -n 1 /etc/group
hadoop1:x:505:
3、手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
[root@mageedu home]# vim /etc/passwd
hadoop:x:505:499::/home/hadoop:/bin/bash
[root@mageedu home]# id hadoop
uid=505(hadoop) gid=499(hadoop) groups=499(hadoop)
[root@mageedu home]# echo 'hadoop1:x:506:505::/home/hadpood1:/bin/bash' >> /etc/passwd
[root@mageedu home]# id hadoop1
uid=506(hadoop1) gid=505(hadoop1) groups=505(hadoop1)
4、复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。
[root@mageedu home]# cp -r /etc/skel /home/hadoop
[root@mageedu home]# ll
total 44
drwx------. 2 bash bash 4096 Aug 13 12:01 bash
drwx------. 2 basher basher 4096 Aug 13 12:01 basher
drwxr-xr-x. 2 root root 4096 Aug 14 14:22 hadoop
drwx------. 2 mageia mageia 4096 Aug 14 01:14 linux
drwx------. 2 1005 distro 4096 Aug 14 01:12 mandriva
drwx------. 2 nologin nologin 4096 Aug 13 12:01 nologin
drwx------. 2 openstack clouds 4096 Aug 14 01:50 openstack
drwx------. 2 slackware distro 4096 Aug 14 01:24 slackware
drwx------. 2 testbash testbash 4096 Aug 13 12:01 testbash
d-wxr-x--x. 2 root root 4096 Aug 14 13:58 tuser1
drwx------. 2 zengzy zengzy 4096 Aug 13 08:28 zengzy
[root@mageedu home]# chmod g-r,o-r hadoop/
[root@mageedu home]# ll
total 44
drwx------. 2 bash bash 4096 Aug 13 12:01 bash
drwx------. 2 basher basher 4096 Aug 13 12:01 basher
drwx--x--x. 2 root root 4096 Aug 14 14:22 hadoop
drwx------. 2 mageia mageia 4096 Aug 14 01:14 linux
drwx------. 2 1005 distro 4096 Aug 14 01:12 mandriva
drwx------. 2 nologin nologin 4096 Aug 13 12:01 nologin
drwx------. 2 openstack clouds 4096 Aug 14 01:50 openstack
drwx------. 2 slackware distro 4096 Aug 14 01:24 slackware
drwx------. 2 testbash testbash 4096 Aug 13 12:01 testbash
d-wxr-x--x. 2 root root 4096 Aug 14 13:58 tuser1
drwx------. 2 zengzy zengzy 4096 Aug 13 08:28 zengzy
5、修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
[root@mageedu home]# ll
total 44
drwx------. 2 bash bash 4096 Aug 13 12:01 bash
drwx------. 2 basher basher 4096 Aug 13 12:01 basher
drwx--x--x. 2 root root 4096 Aug 14 14:22 hadoop
drwx------. 2 mageia mageia 4096 Aug 14 01:14 linux
drwx------. 2 1005 distro 4096 Aug 14 01:12 mandriva
drwx------. 2 nologin nologin 4096 Aug 13 12:01 nologin
drwx------. 2 openstack clouds 4096 Aug 14 01:50 openstack
drwx------. 2 slackware distro 4096 Aug 14 01:24 slackware
drwx------. 2 testbash testbash 4096 Aug 13 12:01 testbash
d-wxr-x--x. 2 root root 4096 Aug 14 13:58 tuser1
drwx------. 2 zengzy zengzy 4096 Aug 13 08:28 zengzy
[root@mageedu home]# chown -R hadoop:hadoop hadoop/
[root@mageedu home]# ll
total 44
drwx------. 2 bash bash 4096 Aug 13 12:01 bash
drwx------. 2 basher basher 4096 Aug 13 12:01 basher
drwx--x--x. 2 hadoop hadoop 4096 Aug 14 14:22 hadoop
drwx------. 2 mageia mageia 4096 Aug 14 01:14 linux
drwx------. 2 1005 distro 4096 Aug 14 01:12 mandriva
drwx------. 2 nologin nologin 4096 Aug 13 12:01 nologin
drwx------. 2 openstack clouds 4096 Aug 14 01:50 openstack
drwx------. 2 slackware distro 4096 Aug 14 01:24 slackware
drwx------. 2 testbash testbash 4096 Aug 13 12:01 testbash
d-wxr-x--x. 2 root root 4096 Aug 14 13:58 tuser1
drwx------. 2 zengzy zengzy 4096 Aug 13 08:28 zengzy
6、显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;
[root@mageedu home]# cat /proc/meminfo | grep "^[sS]"
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 236 kB
Slab: 106148 kB
SReclaimable: 46064 kB
SUnreclaim: 60084 kB
[root@mageedu home]# cat /proc/meminfo | grep -i "^s"
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 236 kB
Slab: 106144 kB
SReclaimable: 46060 kB
SUnreclaim: 60084 kB
7、显示/etc/passw d文件中其默认shell为非/sbin/nologin的用户;
[root@mageedu home]# cat /etc/passwd | grep -v "/sbin/nologin$" | cut -d: -f1
root
sync
shutdown
halt
zengzy
bash
basher
testbash
mageia
slackware
openstack
hadoop
hadoop1
8、显示/etc/passw d文件中其默认shell为/bin/bash的用户;
[root@mageedu home]# cat /etc/passwd | grep "/bin/bash$" | cut -d: -f1
root
zengzy
bash
basher
testbash
mageia
openstack
hadoop
hadoop1
9、找出/etc/passw d文件中的一位数或两位数;
[root@mageedu home]# egrep "\<[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
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
[root@mageedu home]# grep --color=auto "\<[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
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
10、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
[root@mageedu home]# grep "^[[:space:]]\+" /boot/grub/grub.conf
root (hd0,0)
kernel /vmlinuz-2.6.32-642.4.2.el6.x86_64 ro root=UUID=b175aee5-62ee-4625-8aac-f3c455133efa rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-642.4.2.el6.x86_64.img
root (hd0,0)
kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=UUID=b175aee5-62ee-4625-8aac-f3c455133efa rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-642.el6.x86_64.img
11、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
[root@mageedu home]# grep "^#[[:space:]]\+[^[:space:]]\+" /etc/rc.d/rc.sysinit
12、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;
[root@mageedu home]# netstat -tan | egrep "LISTTEN|[[:space:]]$"
Proto Recv-Q Send-Q Local Address Foreign Address State
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
tcp 0 64 192.168.2.105:22 192.168.2.106:12341 ESTABLISHED
tcp 0 0 192.168.2.105:22 192.168.2.106:3099 ESTABLISHED
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:25 :::* LISTEN
13、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;
[root@mageedu home]# useradd bash
[root@mageedu home]# useradd tetstbash
[root@mageedu home]# useradd basher
[root@mageedu home]# useradd -s /sbin/nologin nologin
[root@mageedu home]# grep --color=auto "^\([[:alnum:]]\+\>\).*\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:501:501::/home/bash:/bin/bash
nologin:x:504:504::/home/nologin:/sbin/nologin