第四周作業(yè)
1、復(fù)制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內(nèi)部文件的屬組和其它用戶均沒(méi)有任何訪問(wèn)權(quán)限。
使用到命令chmod
chmod 修改文件或目錄權(quán)限
chmod [option] MODE file
option
-R 遞歸修改
[root@localhost ~]# cp -r /etc/skel /home/tuser1 [root@localhost ~]# ll /home/tuser1 -d drwxr-xr-x 2 root root 59 Feb 2 12:30 /home/tuser1 [root@localhost ~]# chmod 700 /home/tuser1 [root@localhost ~]# ll /home/tuser1/ -d drwx------ 2 root root 59 Feb 2 12:30 /home/tuser1/
2、編輯/etc/group文件,添加組hadoop。
[root@localhost ~]# echo "hadoop:x:3007:" >>/etc/group [root@localhost ~]# tail -1 /etc/group
3、手動(dòng)編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號(hào);其家目錄為/home/hadoop。
[root@localhost ~]# echo "hadoop:x:3007::3007::/home/hadoop:/bin/bash" >> /etc/passwd
4、復(fù)制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒(méi)有任何訪問(wèn)權(quán)限。
[root@localhost ~]# cp -a /etc/skel/ /home/hadoop [root@localhost ~]# chmod 700 /home/hadoop [root@localhost ~]# ll -d /home/hadoop/ drwx------. 2 root root 59 Oct 27 18:20 /home/hadoop/
5、修改/home/hadoop目錄及其內(nèi)部所有文件的屬主為hadoop,屬組為hadoop。
[root@localhost ~]# chown -R hadoop:hadoop /home/hadoop [root@localhost ~]# ll -d /home/hadoop/ drwx------. 2 hadoop hadoop 59 Oct 27 18:20 /home/hadoop/
6、顯示/proc/meminfo文件中以大寫(xiě)或小寫(xiě)S開(kāi)頭的行;用兩種方式;
使用到命令grep 文本過(guò)濾工具
grep [option] PATTERN file
option
-i 忽略大小寫(xiě)
-o 只顯示匹配到的文本
-v 只顯示不匹配的文本
-E 支持?jǐn)U展正則表達(dá)式
-q 不輸出任何內(nèi)容
-A # 后#行
-B # 前#行
-C # 前后各#行
PATTERN支持使用正則表達(dá)式和擴(kuò)展的正則表達(dá)式
方法1
[root@localhost ~]# grep -i ^s /proc/meminfo SwapCached: 0 kB SwapTotal: 1048572 kB SwapFree: 1048572 kB Shmem: 4676 kB Slab: 51208 kB SReclaimable: 26556 kB SUnreclaim: 24652 kB
方法2
[root@localhost ~]# grep ^[s,S] /proc/meminfo SwapCached: 0 kB SwapTotal: 1048572 kB SwapFree: 1048572 kB Shmem: 4676 kB Slab: 51208 kB SReclaimable: 26556 kB SUnreclaim: 24652 kB
方法3
[root@localhost ~]# grep -E "^(s|S)" /proc/meminfo SwapCached: 0 kB SwapTotal: 1048572 kB SwapFree: 1048572 kB Shmem: 4676 kB Slab: 51208 kB SReclaimable: 26556 kB SUnreclaim: 24652 kB
7、顯示/etc/passwd文件中其默認(rèn)shell為非/sbin/nologin的用戶;
[root@localhost ~]# grep -v "/sbin/nologin" /etc/passwd| cut -d: -f 1 root sync shutdown halt mageia slackware clouds openstack hadoop
8、顯示/etc/passwd文件中其默認(rèn)shell為/bin/bash的用戶;
[root@localhost ~]# grep "/bin/bash" /etc/passwd| cut -d: -f 1 root mageia clouds openstack hadoop
9、找出/etc/passwd文件中的一位數(shù)或兩位數(shù);
[root@localhost ~]# 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 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 avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/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/grub/grub.conf中以至少一個(gè)空白字符開(kāi)頭的行;
[root@localhost ~]# grep -E ^" " /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 if [ x$feature_all_video_module = xy ]; then insmod all_video else insmod efi_gop insmod efi_uga insmod ieee1275_fb insmod vbe insmod vga insmod video_bochs insmod video_cirrus fi set timeout_style=menu set timeout=5 set timeout=5 source ${prefix}/user.cfg if [ -n ${GRUB2_PASSWORD} ]; then set superusers="root" export superusers password_pbkdf2 root ${GRUB2_PASSWORD} fi source ${config_directory}/custom.cfg source $prefix/custom.cfg; [root@localhost ~]# grep ^" " /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 if [ x$feature_all_video_module = xy ]; then insmod all_video else insmod efi_gop insmod efi_uga insmod ieee1275_fb insmod vbe insmod vga insmod video_bochs insmod video_cirrus fi set timeout_style=menu set timeout=5 set timeout=5 source ${prefix}/user.cfg if [ -n ${GRUB2_PASSWORD} ]; then set superusers="root" export superusers password_pbkdf2 root ${GRUB2_PASSWORD} fi source ${config_directory}/custom.cfg source $prefix/custom.cfg;
11、顯示/etc/rc.d/rc.sysinit文件中以#開(kāi)頭,后面跟至少一個(gè)空白字符,而后又有至少一個(gè)非空白字符的行;
[root@localhost ~]# grep -E "^#[[: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命令執(zhí)行結(jié)果中以‘LISTEN’,后或跟空白字符結(jié)尾的行;
[root@localhost ~]# netstat -tan|grep "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 :::22 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN
13、添加用戶bash, testbash, basher, nologin (此一個(gè)用戶的shell為/sbin/nologin),而后找出當(dāng)前系統(tǒng)上其用戶名和默認(rèn)shell相同的用戶的信息;
[root@localhost ~]# grep -E "^(\<[[: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:3007:3008::/home/bash:/bin/bash nologin:x:3010:3011::/home/nologin:/sbin/nologin [root@localhost ~]# grep "^\([[: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:3007:3008::/home/bash:/bin/bash nologin:x:3010:3011::/home/nologin:/sbin/nologin
14、顯示/proc/meminfo文件中以大寫(xiě)或小寫(xiě)S開(kāi)頭的行;用三種方式;
方法1 [root@localhost ~]# grep -i ^s /proc/meminfo SwapCached: 0 kB SwapTotal: 1048572 kB SwapFree: 1048572 kB Shmem: 4676 kB Slab: 51208 kB SReclaimable: 26556 kB SUnreclaim: 24652 kB 方法2 [root@localhost ~]# grep ^[s,S] /proc/meminfo SwapCached: 0 kB SwapTotal: 1048572 kB SwapFree: 1048572 kB Shmem: 4676 kB Slab: 51208 kB SReclaimable: 26556 kB SUnreclaim: 24652 kB 方法3 [root@localhost ~]# grep -E "^(s|S)" /proc/meminfo SwapCached: 0 kB SwapTotal: 1048572 kB SwapFree: 1048572 kB Shmem: 4676 kB Slab: 51208 kB SReclaimable: 26556 kB SUnreclaim: 24652 kB
15、顯示/etc/passwd文件中其默認(rèn)shell為非/sbin/nologin的用戶;
[root@localhost ~]# grep -E "/sbin/nologin$" /etc/passwd |cut -d: -f1 bin daemon adm lp mail operator games ftp nobody avahi-autoipd systemd-bus-proxy systemd-network dbus polkitd tss postfix sshd mysql nologin
16、顯示/etc/passwd文件中其默認(rèn)shell為/bin/bash的用戶;
[root@localhost ~]# grep -E "/bin/bash$" /etc/passwd |cut -d: -f1 root mageia clouds openstack hadoop bash testbash basher
17、找出/etc/passwd文件中的一位數(shù)或兩位數(shù);
[root@localhost ~]# 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 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