一、複製/etc/skel目錄爲/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。linux
Linux的權限管理:
ios
文件的權限主要針對三類對象進行管理:
shell
owner:屬主 ucentos
group:屬組 gbash
other:其它 oapp
每一個文件針對每類訪問者都定義了三種權限:tcp
r:Readableide
w:writable工具
x:eXcutableoop
文件:
r:可以使用文件查看類工具獲取其內容
w:可修改其內容
x:能夠把此文件提請內核啓動爲一個進程
目錄:
r:可使用ls查看此目錄中文件列表
w:可在此目錄中建立文件,也可刪除此目錄中的文件
x:可使用ls -l 查看此目錄中文件列表,能夠cd進入此目錄
用八進制表示權限的方式:
--- 000 0
--x 001 1
-w- 010 2
-wx 011 3
r-- 100 4
r-x 101 5
rw- 110 6
rwx 111 7
chmod命令:更改文件權限
用法: chmod [OPTION]... MODE[,MODE]... FILE...
or: chmod [OPTION]... OCTAL-MODE FILE... //經過八進制更改文件權限
or: chmod [OPTION]... --reference=RFILE FILE...
mode: 權限設定字串,格式以下 : [ugoa...][[+-=][rwx]...][,...],其中
u:屬主
g:屬組
o:其它
a:全部用戶
+:添加權限
-:刪除權限
=:賦值權限
經常使用選項:
-c,--changes
只輸出被改變文件的信息
-f,--silent,--quiet
當chmod不能改變文件模式時,不通知文件的用戶
--help
輸出幫助信息。
-R,--recursive
可遞歸遍歷子目錄,把修改應到目錄下全部文件和子目錄
--reference=filename
參照filename的權限來設置權限
-v,--verbose
不管修改是否成功,輸出每一個文件的信息
[root@localhost home]# cp -r /etc/skel/ ./tuser1/ //-r複製目錄 [root@localhost home]# chmod -R go= tuser1/ [root@localhost tuser1]# ll -a total 16 drwx------. 3 root root 74 Aug 26 23:01 . drwx------. 9 root root 4096 Aug 26 23:01 .. -rw-------. 1 root root 18 Aug 26 23:01 .bash_logout -rw-------. 1 root root 193 Aug 26 23:01 .bash_profile -rw-------. 1 root root 231 Aug 26 23:01 .bashrc drwx------. 4 root root 37 Aug 26 23:01 .mozilla
二、編輯/etc/group文件,添加組hadoop。
hadoop:x:3005:
三、手動編輯/etc/passw d文件新增一行,添加用戶hadoop,其基本組ID爲hadoop組的id號;其家目錄爲/home/hadoop。
hadoop:x:3005:3005::/home/hadoop:/bin/bash
四、複製/etc/skel目錄爲/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒有任何訪問權限。
[root@localhost home]# chmod -R go= hadoop [root@localhost home]# ll total 8 drwx------. 3 root root 74 Aug 27 02:10 hadoop drwx------. 3 hadoop 3006 74 Aug 27 02:06 june drwx------. 15 jun_shao jun_shao 4096 Aug 26 21:26 jun_shao drwx------. 3 mageia mageia 74 Aug 20 08:06 linux drwx------. 3 1005 distro 74 Aug 20 08:05 mandriva drwx------. 5 openstack clouds 4096 Aug 21 00:56 openstack drwx------. 3 slackware distro 74 Aug 20 08:25 slackware drwx------. 3 root root 74 Aug 26 23:01 tuser1 drwx------. 3 user1 user1 74 Aug 21 10:36 user1
五、修改/home/hadoop目錄及其內部全部文件的屬主爲hadoop,屬組爲hadoop。
chown命令:更改文件的屬主屬組
用法:chown [OPTION]... [OWNER][:[GROUP]] FILE...
chown [OPTION]... --reference=RFILE FILE...
選項:
-c 顯示更改的部分的信息
-f 忽略錯誤信息
-h 修復符號連接
-R 處理指定目錄以及其子目錄下的全部文件
-v 顯示詳細的處理信息
-deference 做用於符號連接的指向,而不是連接文件自己
[root@localhost home]# chown -R hadoop hadoop/
六、顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用兩種方式;
[root@localhost home]# cat /proc/meminfo | grep '^[s|S]' //[]匹配括號中的單個字符,^括號外面表示以某個字符開頭,|表示或 SwapCached: 72 kB SwapTotal: 2097148 kB SwapFree: 2094544 kB Shmem: 5952 kB Slab: 83580 kB SReclaimable: 31844 kB SUnreclaim: 51736 kB [root@localhost home]# cat /proc/meminfo | grep '\<[S|s]' //\<錨定字符串的開始 SwapCached: 64 kB SwapTotal: 2097148 kB SwapFree: 2094552 kB Shmem: 5960 kB Slab: 83580 kB SReclaimable: 31844 kB SUnreclaim: 51736 kB
七、顯示/etc/passw d文件中其默認shell爲非/sbin/nologin的用戶;
[root@localhost home]# cat /etc/passwd | grep -v '/sbin/nologin\>' //-v取反 \>錨定字符串的結束 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 amandabackup:x:33:6:Amanda user:/var/lib/amanda:/bin/bash jun_shao:x:1000:1000:jun_shao:/home/jun_shao:/bin/bash mageia:x:1100:1100::/home/linux:/bin/bash slackware:x:2002:2016::/home/slackware:/bin/tcsh openstack:x:3003:2019::/home/openstack:/bin/bash user1:x:3004:3004::/home/user1:/bin/bash hadoop:x:3005:3005::/home/hadoop:/bin/bash [root@localhost home]# cat /etc/passwd | grep -v '/sbin/nologin\>' | cut -d: -f1 root sync shutdown halt amandabackup jun_shao mageia slackware openstack user1 hadoop
八、顯示/etc/passw d文件中其默認shell爲/bin/bash的用戶;
[root@localhost home]# grep '/bin/bash\>' /etc/passwd | cut -d: -f1 root amandabackup jun_shao mageia openstack user1 hadoop
九、找出/etc/passw d文件中的一位數或兩位數;
[root@localhost ~]# grep -o '\<[0-9]\{1,2\}' /etc/passwd //-o顯示匹配的內容,{}表示區間,匹配[0-9]兩次 0 0 1 1 2 2 3 4 4 7 5 0 6 0 7 0 8 12 11 0 12 10 14 50 99 99 17 17 99 99 99 99 81 81 99 99 17 17 59 59 99 99 11 11 99 99 33 6 99 76 99 99 99 98 32 32 99 98 17 17 38 38 10 10 29 29 65 65 75 75 99 98 98 98 17 17 42 42 98 98 70 70 89 89 74 74 72 72 10 10 11 11 20 20 30 20 98 98 30 30 30 30 30 30 30 30 30 30 30 30
十、顯示/boot/grub/grub.conf中以致少一個空白字符開頭的行;
[root@localhost home]# grep '^[[:space:]]\+' /boot/grub2/grub.cfg //[:space:]表示空白字符,+表示匹配0次或屢次 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 load_video set gfxpayload=keep insmod gzio insmod part_msdos insmod xfs set root='hd0,msdos1' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' be50a901-277e-4252-b8be-717299df19f5 else search --no-floppy --fs-uuid --set=root be50a901-277e-4252-b8be-717299df19f5 fi linux16 /vmlinuz-3.10.0-327.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8 initrd16 /initramfs-3.10.0-327.el7.x86_64.img load_video insmod gzio insmod part_msdos insmod xfs set root='hd0,msdos1' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' be50a901-277e-4252-b8be-717299df19f5 else search --no-floppy --fs-uuid --set=root be50a901-277e-4252-b8be-717299df19f5 fi linux16 /vmlinuz-0-rescue-5c7c63d6669b43fa947518735648b83b root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet initrd16 /initramfs-0-rescue-5c7c63d6669b43fa947518735648b83b.img source ${config_directory}/custom.cfg
十一、顯示/etc/rc.d/rc.sysinit文件中以#開頭,後面跟至少一個空白字符,然後又有至少一個非空白字符的行;
[root@localhost home]# grep '^#[[:space:]]\+[^[:space:]]' /boot/grub2/grub.cfg # DO NOT EDIT THIS FILE # It is automatically generated by grub2-mkconfig using templates # from /etc/grub.d and settings from /etc/default/grub # Fallback normal timeout code in case the timeout_style feature is # unavailable. # This file provides an easy way to add custom menu entries. Simply type the # menu entries you want to add after this comment. Be careful not to change # the 'exec tail' line above.
十二、打出netstat -tan命令執行結果中以‘LISTEN’,後或跟空白字符結尾的行;
[root@localhost home]# netstat -tan | grep 'LISTEN[[:space:]]*$' tcp 0 0 192.168.122.1:53 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 tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:631 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN
1三、添加用戶bash, testbash, basher, nologin (此一個用戶的shell爲/sbin/nologin),然後找出當前系統上其用戶名和默認shell相同的用戶的信息;
[root@localhost home]# 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:3006:3006::/home/bash:/bin/bash nologin:x:3009:3009::/home/nologin:/sbin/nologin