N21第四周博客作業
1、 復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。
[root@Centos6 ~]# cp -r /etc/skel /home/tuser1 [root@Centos6 ~]#chmod –R og=------ /home/tuser1/ [root@Centos6 ~]# ll -d /home/tuser1 drwx------. 3 root root 4096 7月 14 04:16 /home/tuser1
2、 編輯/etc/group文件,添加組hadoop。
[root@Centos6 ~]# echo "hadoop:x:600:">>/etc/group [root@Centos6 ~]# tail -1 /etc/group hadoop:x:600:
3、 手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop。
[root@Centos6 ~]# echo "hadoop:x:600:600::/home/hadoop:/bin/bash">>/etc/passwd [root@Centos6 ~]# tail -1 /etc/passwd hadoop:x:600:600::/home/hadoop:/bin/bash
4、 復制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒有任何訪問權限。
[root@Centos6 ~]# cp -r /etc/skel /home/hadoop [root@Centos6 home]# chmod og=------ /home/hadoop [root@Centos6 home]# ll drwx------. 3 root root 4096 7月 14 05:53 hadoop
5、 修改/home/hadoop目錄及其內部所有文件的屬主為hadoop,屬組為hadoop。
[root@Centos6 home]# chown -R hadoop:hadoop hadoop [root@Centos6 home]# ll drwx------. 3 hadoop hadoop 4096 7月 14 05:53 hadoop
6、 顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用兩種方式;
[root@Centos6 home]# grep -i '^s.*' /proc/meminfo SwapCached: 2712 kB SwapTotal: 2031608 kB SwapFree: 2021016 kB Shmem: 28 kB Slab: 152116 kB SReclaimable: 95700 kB SUnreclaim: 56416 kB
[root@Centos6 home]# grep -i '^[s,S].*' /proc/meminfo SwapCached: 2712 kB SwapTotal: 2031608 kB SwapFree: 2021016 kB Shmem: 28 kB Slab: 152128 kB SReclaimable: 95700 kB SUnreclaim: 56428 kB
7、 顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶;
[root@Centos6 ~]# 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 jenkins:x:498:498:Jenkins Continuous Integration Server:/var/lib/jenkins:/bin/false hadoop:x:500:600::/home/hadoop:/bin/bash
8、 顯示/etc/passwd文件中其默認shell為/bin/bash的用戶;
[root@Centos6 ~]# grep '/bin/bash' /etc/passwd root:x:0:0:root:/root:/bin/bash hadoop:x:500:600::/home/hadoop:/bin/bash
9、 找出/etc/passwd文件中的一位數或兩位數;
[root@Centos6 ~]# grep -o '\<[0-9]\{1,2\}\>' /etc/passwd 0 0 1 4 7 5 29 29 74 74 72 72 16
10、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;
[root@Centos6 ~]# grep -E '^[[:space:]]+' /boot/grub/grub.conf root (hd0,0) kernel /vmlinuz-2.6.32-279.el6.x86_64…………. initrd /initramfs-2.6.32-279.el6.x86_64.img
11、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;
[root@Centos6 ~]# grep -E '^#+[[:space:]]+[[:graph:]]+' /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
12、打出netstat -tan命令執行結果中以‘LISTEN’,后或跟空白字符結尾的行;
[root@Centos6 ~]# cls [root@Centos6 ~]# netstat -tan | grep -E 'LISTEN[[:space:]]+$' tcp 0 0 0.0.0.0:39750 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 :::37670 :::* LISTEN
13、 添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息;
[root@Centos6 ~]# grep '^\([[:alpha:]]\+\>\).*\1$' /etc/passwd sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown bash:x:541:541::/home/bash:/bin/bash nologin:x:545:545::/home/nologin:/sbin/nologin
14、顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用三種方式;
[root@Centos6 ~]# grep -E "^(s|S).*" /proc/meminfo [root@Centos6 ~]# grep '[s,S].*' /proc/meminfo [root@Centos6 ~]# grep -i '^s.*' /proc/meminfo
原創文章,作者:N21-沉舟,如若轉載,請注明出處:http://www.www58058.com/24239
寫的很好,排版也很漂亮,加油