本周作业内容:
1、 复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。
#cp -r /etc/skel//home/tuser1
#chmod -R 700tuser1/
2、 编辑/etc/group文件,添加组hadoop。
#vim /etc/group
#tail -n 5/etc/group
3、 手动编辑/etc/passw d文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
# vim /etc/passwd
# id hadoop
4、 复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。
# cp -r/etc/skel /home/hadoop
# chmod -R 711 hadoop
5、 修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
# chown –R hadoop:hadoop /home/hadoop
[root@hiall2016 home]# chown -R hadoop:hadoop /home/hadoop
[root@hiall2016 home]# ll
total 20
-rwxrwxrwx. 1 root root 315 Aug 17 13:36 addSvnUser.sh
drwx------. 2 fucheng fucheng 59 Mar 23 13:47 fucheng
drwx------. 2 guoxingfei guoxingfei 59 Mar 23 13:47 guoxingfei
drwx--x--x. 2 hadoop hadoop 59 Aug 28 23:04 hadoop
6、 显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;
[root@hiall2016~]# cat /proc/meminfo | grep "^[sS]"
SwapCached: 278496 kB
SwapTotal: 10485756 kB
SwapFree: 9389804 kB
Shmem: 140384 kB
Slab: 301940 kB
SReclaimable: 211872 kB
SUnreclaim: 90068 kB
[root@hiall2016~]# cat /proc/meminfo | grep -i "^s"
SwapCached: 278496 kB
SwapTotal: 10485756 kB
SwapFree: 9389804 kB
Shmem: 140384 kB
Slab: 301932 kB
SReclaimable: 211888 kB
SUnreclaim: 90044 kB
7、 显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;
[root@hiall2016~]# cat /etc/passwd | grep -v "/sbin/nologin$"
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
niejiansong:x:1000:1000:niejiansong:/home/niejiansong:/bin/bash
nginx:x:1001:1001::/home/nginx:/bin/bash
mysql:x:27:27:MySQLServer:/var/lib/mysql:/bin/bash
kzxj2016:x:1002:1003::/home/kzxj2016:/bin/bash
yulai:x:1003:1004::/home/yulai:/bin/bash
huanqing:x:1004:1005::/home/huanqing:/bin/bash
guoxingfei:x:1005:1006::/home/guoxingfei:/bin/bash
ningkeke:x:1006:1007::/home/ningkeke:/bin/bash
fucheng:x:1007:1008::/home/fucheng:/bin/bash
yuliyang:x:1008:1009::/home/yuliyang:/bin/bash
jacknie:x:1009:1010::/home/jacknie:/bin/bash
tomcat:x:1010:1011::/home/tomcat:/bin/bash
shidawang:x:1012:1014::/home/shidawang:/bin/bash
haoran:x:1013:1015::/home/haoran:/bin/bash
hrwb1:x:1014:1016::/home/hrwb1:/bin/bash
hrwb2:x:1015:1017::/home/hrwb2:/bin/bash
hadoop:x:505:499::/home/hadoop:/bin/bash
[root@hiall2016 ~]# cat /etc/passwd | grep -v "/sbin/nologin$" | cut -d: -f1
root
sync
shutdown
halt
niejiansong
nginx
mysql
kzxj2016
yulai
huanqing
guoxingfei
ningkeke
fucheng
yuliyang
jacknie
tomcat
shidawang
haoran
hrwb1
hrwb2
hadoop
8、 显示/etc/passw d文件中其默认shell为/bin/bash的用户;
[root@hiall2016 ~]# cat /etc/passwd | grep"/bin/bash$" | cut -d: -f1
root
niejiansong
nginx
mysql
kzxj2016
yulai
huanqing
guoxingfei
ningkeke
fucheng
yuliyang
jacknie
tomcat
shidawang
haoran
hrwb1
hrwb2
hadoop
9、 找出/etc/passw d文件中的一位数或两位数;
[root@hiall2016 ~]# 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
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 messagebus:/:/sbin/nologin
tss:x:59:59:Account used by the trouserspackage to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separatedSSH:/var/empty/sshd:/sbin/nologin
mysql:x:27:27:MySQLServer:/var/lib/mysql:/bin/bash
ntp:x:38:38::/etc/ntp:/sbin/nologin
[root@hiall2016 ~]# 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
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTPUser:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System messagebus:/:/sbin/nologin
tss:x:59:59:Account used by the trouserspackage to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separatedSSH:/var/empty/sshd:/sbin/nologin
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
ntp:x:38:38::/etc/ntp:/sbin/nologin
[root@hiall2016 ~]# 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
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTPUser:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System messagebus:/:/sbin/nologin
tss:x:59:59:Account used by the trouserspackage to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separatedSSH:/var/empty/sshd:/sbin/nologin
mysql:x:27:27:MySQLServer:/var/lib/mysql:/bin/bash
ntp:x:38:38::/etc/ntp:/sbin/nologin
10、 显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
# grep"^[[:space:]]\+" /boot/grub/grub.conf
11、 显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
#netstat -tan | egrep "LISTTEN|[[:space:]]$"
12、 打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;
[root@hiall2016 ~]# netstat -tan | egrep"LISTTEN|[[:space:]]$"
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3690 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:25 0.0.0.0:* LISTEN
tcp6 0 0 :::8009 :::* LISTEN
tcp6 0 0 :::3306 :::* LISTEN
tcp6 0 0 127.0.0.1:8011 :::* LISTEN
tcp6 0 0 127.0.0.1:8012 :::* LISTEN
tcp6 0 0 127.0.0.1:8013 :::* LISTEN
tcp6 0 0 127.0.0.1:8014 :::* LISTEN
tcp6 0 0 :::8015 :::* LISTEN
tcp6 0 0 :::8016 :::* LISTEN
tcp6 0 0 :::8080 :::* LISTEN
tcp6 0 0 :::8017 :::* LISTEN
tcp6 0 0 :::8081 :::* LISTEN
tcp6 0 0 :::8018 :::* LISTEN
tcp6 0 0 :::8082 :::* LISTEN
tcp6 0 0 :::8083 :::* LISTEN
tcp6 0 0 :::8084 :::* LISTEN
tcp6 0 0 :::8021 :::* LISTEN
tcp6 0 0 127.0.0.1:8022 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 :::8087 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
tcp6 0 0 127.0.0.1:8005 :::* LISTEN
tcp6 70 0 192.168.1.252:44533 218.28.133.181:443 CLOSE_WAIT
tcp6 70 0 192.168.1.252:45528 218.28.133.181:443 CLOSE_WAIT
tcp6 70 0 192.168.1.252:39893 218.28.133.181:443
CLOSE_WAIT
13、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用
户的信息;
[root@hiall2016~]# useradd bash
[root@hiall2016~]# useradd tetstbash
[root@hiall2016~]# useradd basher
[root@hiall2016~]# useradd -s /sbin/nologin nologin
[root@hiall2016~]# 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:1016:1018::/home/bash:/bin/bash
nologin:x:1019:1021::/home/nologin:/sbin/nologin