马哥教育网络班20期+第4周课程练习
1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。
# cp -a /etc/skel /home/tuser1 # chmod -R go-rx /hom/tuser1 实例演示 [root@C664BSLab ~]# cp -a /etc/skel /home/tuser1 [root@C664BSLab ~]# ll -d /home/tuser1 drwxr-xr-x. 2 root root 4096 Jun 27 23:19 /home/tuser1 [root@C664BSLab ~]# chmod -R go-rx /home/tuser1 [root@C664BSLab ~]# ll -d /home/tuser1 drwx------. 2 root root 4096 Jun 27 23:19 /home/tuser1 [root@C664BSLab ~]# ll -a /home/tuser1/ total 20 drwx------. 2 root root 4096 Jun 27 23:19 . drwxr-xr-x. 6 root root 4096 Jul 3 02:45 .. -rw-------. 1 root root 18 May 11 07:21 .bash_logout -rw-------. 1 root root 176 May 11 07:21 .bash_profile -rw-------. 1 root root 124 May 11 07:21 .bashrc
2、编辑/etc/group文件,添加组hadoop。
# echo "hadoop:x:501:" >> /etc/group 实例演示 [root@C664BSLab ~]# tail -1 /etc/group centos:x:500: [root@C664BSLab ~]# echo "hadoop:x:501:" >> /etc/group [root@C664BSLab ~]# tail -1 /etc/group hadoop:x:501:
3、手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组ID为hadoop组的id号;其家目录为/home/hadoop。
# echo "hadoop:x:501:501::/home/hadoop:/bin/bash" >> /etc/passwd 实例演示 [root@C664BSLab ~]# tail -1 /etc/passwd centos:x:500:500::/home/centos:/bin/bash [root@C664BSLab ~]# echo "hadoop:x:501:501::/home/hadoop:/bin/bash" >> /etc/passwd [root@C664BSLab ~]# tail -1 /etc/passwd hadoop:x:501:501::/home/hadoop:/bin/bash
4、复制/etc/skel目录为/home/hadoop,要求修改hadoop目录的属组和其它用户没有任何访问权限。
# cp -a /etc/skel /home/hadoop # chmod go-rx /home/hadoop 实例演示 [root@C664BSLab ~]# cp -a /etc/skel /home/hadoop [root@C664BSLab ~]# ll -d /home/hadoop drwxr-xr-x. 2 root root 4096 Jun 27 23:19 /home/hadoop [root@C664BSLab ~]# chmod go-rx /home/hadoop [root@C664BSLab ~]# ll -d /home/hadoop drwx------. 2 root root 4096 Jun 27 23:19 /home/hadoop
5、修改/home/hadoop目录及其内部所有文件的属主为hadoop,属组为hadoop。
# chown -R hadoop:hadoop /home/hadoop 实例演示 [root@C664BSLab ~]# chown -R hadoop:hadoop /home/hadoop [root@C664BSLab ~]# ll -d /home/hadoop drwx------. 2 hadoop hadoop 4096 Jun 27 23:19 /home/hadoop
6、显示/proc/meminfo文件中以大写或小写S开头的行;用两种方式;
# grep -i "^[s]" /proc/meminfo # grep "^[Ss]" /proc/meminfo 实例演示 [root@C664BSLab ~]# grep -i "^s" /proc/meminfo SwapCached: 0 kB SwapTotal: 2031612 kB SwapFree: 2031612 kB Shmem: 196 kB Slab: 93404 kB SReclaimable: 32680 kB SUnreclaim: 60724 kB [root@C664BSLab ~]# grep "^[Ss]" /proc/meminfo SwapCached: 0 kB SwapTotal: 2031612 kB SwapFree: 2031612 kB Shmem: 196 kB Slab: 93396 kB SReclaimable: 32676 kB SUnreclaim: 60720 kB
7、显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;
# grep -v "/sbin/nologin$" /etc/passwd 实例演示 [root@C664BSLab ~]# 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 centos:x:500:500::/home/centos:/bin/bash hadoop:x:501:501::/home/hadoop:/bin/bash
8、显示/etc/passwd文件中其默认shell为/bin/bash的用户;
# grep "/bin/bash$" /etc/passwd 实例演示 [root@C664BSLab ~]# grep "/bin/bash$" /etc/passwd root:x:0:0:root:/root:/bin/bash centos:x:500:500::/home/centos:/bin/bash hadoop:x:501:501::/home/hadoop:/bin/bash
9、找出/etc/passwd文件中的一位数或两位数;
# grep -E "\<[0-9]{1,2}\>" /etc/passwd 实例演示 [root@C664BSLab ~]# grep -E "\<[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
10、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
# grep -E "^[[:space:]]+" /boot/grub/grub.conf 实例演示 [root@C664BSLab ~]# grep -E "^[[:space:]]+" /boot/grub/grub.conf root (hd0,0) kernel /vmlinuz-2.6.32-573.el6.x86_64 ro root=/dev/mapper/vg_c664bslab-lv_root rd_NO_LUKS.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_c664bslab/lv_swap KEYBOARDTYPE=pc KEYTABLE=us rd_LVM_LV=vg_c664bslab/lv_root rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-573.el6.x86_64.img
11、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
# grep -E "^#[[:space:]]+[^[:space:]]+" /etc/rc.d/rc.sysinit 实例演示 [root@C664BSLab ~]# grep -E "^#[[:space:]]+[^[:space:]]+" /etc/rc.d/rc.sysinit # /etc/rc.d/rc.sysinit - run once at boot time # Taken in part from Miquel van Smoorenburg's bcheckrc. # Check SELinux status # Print a text banner. # Only read this once. # Initialize hardware # Set default affinity # Load other user-defined modules # Load modules (for backward compatibility with VARs)
12、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;
# netstat -tan | grep "LISTEN[[:space:]]*$" 实例演示 [root@C664BSLab ~]# netstat -tan | grep "LISTEN[[:space:]]*$" tcp 0 0 0.0.0.0:39243 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:111 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 tcp 0 0 :::58845 :::* LISTEN tcp 0 0 :::111 :::* LISTEN tcp 0 0 :::22 :::* LISTEN tcp 0 0 ::1:631 :::* LISTEN tcp 0 0 ::1:25 :::* LISTEN
13、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;
# useradd bash # useradd testbash # useradd basher # useradd -s /sbin/nologin nologin # grep -E "^([[:alpha:]]+\>).*\1$" /etc/passwd 实例演示 [root@C664BSLab ~]# useradd bash [root@C664BSLab ~]# useradd testbash [root@C664BSLab ~]# useradd basher [root@C664BSLab ~]# useradd -s /sbin/nologin nologin [root@C664BSLab ~]# tail -4 /etc/passwd bash:x:502:502::/home/bash:/bin/bash testbash:x:503:503::/home/testbash:/bin/bash basher:x:504:504::/home/basher:/bin/bash nologin:x:505:505::/home/nologin:/sbin/nologin [root@C664BSLab ~]# 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:502:502::/home/bash:/bin/bash nologin:x:505:505::/home/nologin:/sbin/nologin
14、显示/proc/meminfo文件中以大写或小写S开头的行;用三种方式;
# grep -i "^s" /proc/meminfo # grep "^[Ss]" /proc/meminfo # grep -iv "^[a-rt-z]" /proc/meminfo 实例演示 [root@C664BSLab ~]# egrep -i "^s" /proc/meminfo SwapCached: 0 kB SwapTotal: 2031612 kB SwapFree: 2031612 kB Shmem: 196 kB Slab: 93428 kB SReclaimable: 32752 kB SUnreclaim: 60676 kB [root@C664BSLab ~]# egrep "^[Ss]" /proc/meminfo SwapCached: 0 kB SwapTotal: 2031612 kB SwapFree: 2031612 kB Shmem: 196 kB Slab: 93428 kB SReclaimable: 32752 kB SUnreclaim: 60676 kB [root@C664BSLab ~]# egrep -iv "^[a-rt-z]" /proc/meminfo SwapCached: 0 kB SwapTotal: 2031612 kB SwapFree: 2031612 kB Shmem: 196 kB Slab: 93428 kB SReclaimable: 32752 kB SUnreclaim: 60676 kB
15、显示/etc/passwd文件中其默认shell为非/sbin/nologin的用户;
# egrep -v "/sbin/nologin$" /etc/passwd 实例演示 [root@C664BSLab ~]# egrep -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 centos:x:500:500::/home/centos:/bin/bash hadoop:x:501:501::/home/hadoop:/bin/bash bash:x:502:502::/home/bash:/bin/bash testbash:x:503:503::/home/testbash:/bin/bash basher:x:504:504::/home/basher:/bin/bash
16、显示/etc/passwd文件中其默认shell为/bin/bash的用户;
# egrep "/bin/bash$" /etc/passwd 实例演示 [root@C664BSLab ~]# egrep "/bin/bash$" /etc/passwd root:x:0:0:root:/root:/bin/bash centos:x:500:500::/home/centos:/bin/bash hadoop:x:501:501::/home/hadoop:/bin/bash bash:x:502:502::/home/bash:/bin/bash testbash:x:503:503::/home/testbash:/bin/bash basher:x:504:504::/home/basher:/bin/bash
17、找出/etc/passwd文件中的一位数或两位数;
# egrep "\<[0-9]{1,2}\>" /etc/passwd 实例演示 [root@C664BSLab ~]# 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
原创文章,作者:N20-背旅,如若转载,请注明出处:http://www.178linux.com/21568
评论列表(1条)
写的很好,排版问题也很棒,加油