N25-第四周作業

第四周

1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。

[root@zf ~]# cp -r /etc/skel/ /home/tuser1
[root@zf ~]# chmod -R go= /home/tuser1/ 

[root@zf ~]# ls -al /home/tuser1/              
總用量 28
d-wx------. 4 root root 4096 12月 16 06:17 .
drwxr-xr-x. 8 root root 4096 12月 16 06:17 ..
-rw-------. 1 root root   18 12月 16 06:17 .bash_logout
-rw-------. 1 root root  176 12月 16 06:17 .bash_profile
-rw-------. 1 root root  124 12月 16 06:17 .bashrc
drwx------. 2 root root 4096 12月 16 06:17 .gnome2
drwx------. 4 root root 4096 12月 16 06:17 .mozilla

2、編輯/etc/group文件,添加組hadoop。

[root@zf ~]# echo "hadoop:x:2021:" >> /etc/group

[root@zf ~]# cat /etc/group | tail -2
nova:x:2020:openstack
hadoop:x:2021:

3、手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop。

[root@zf ~]# echo "hadoop:x:1001:2021::/home/hadoop:/bin/bash" >> /etc/passwd

[root@zf ~]# cat /etc/passwd | tail -2
openstack:x:3003:2019::/home/openstack:/bin/bash
hadoop:x:1001:2021::/home/hadoop:/bin/bash

4、復制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒有任何訪問權限。

[root@zf ~]# cp -r /etc/skel/ /home/hadoop
[root@zf ~]# chmod go= /home/hadoop/    

[root@zf ~]# ls -ld /home/hadoop/
drwx------. 4 root root 4096 12月 16 07:43 /home/hadoop/

5、修改/home/hadoop目錄及其內部所有文件的屬主為hadoop,屬組為hadoop。

[root@zf ~]# chown -R hadoop.hadoop /home/hadoop/
[root@zf ~]# ls -la /home/hadoop/ 

[root@zf ~]# ls -la /home/hadoop/ 
總用量 28
drwx------. 4 hadoop hadoop 4096 12月 16 07:43 .
drwxr-xr-x. 9 root   root   4096 12月 16 07:43 ..
-rw-r--r--. 1 hadoop hadoop   18 12月 16 07:43 .bash_logout
-rw-r--r--. 1 hadoop hadoop  176 12月 16 07:43 .bash_profile
-rw-r--r--. 1 hadoop hadoop  124 12月 16 07:43 .bashrc
drwxr-xr-x. 2 hadoop hadoop 4096 12月 16 07:43 .gnome2
drwxr-xr-x. 4 hadoop hadoop 4096 12月 16 07:43 .mozilla

6、顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用兩種方式;

[root@zf ~]# grep  "^[sS].*" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097144 kB
SwapFree:        2097144 kB
Shmem:               432 kB
Slab:              99732 kB
SReclaimable:      42004 kB
SUnreclaim:        57728 kB 

[root@zf ~]# grep -E "^(s|S).*" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097144 kB
SwapFree:        2097144 kB
Shmem:               432 kB
Slab:              99720 kB
SReclaimable:      42000 kB
SUnreclaim:        57720 kB

7、顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶;

[root@zf ~]# grep -v "/sbin/nologin$" /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
aa
mageia
slackware
openstack
hadoop

8、顯示/etc/passwd文件中其默認shell為/bin/bash的用戶;

[root@zf ~]# cat /etc/passwd | grep  "/bin/bash$" | cut -d: -f1           
root
aa
mageia
openstack
hadoop

9、找出/etc/passwd文件中的一位數或兩位數;

[root@zf ~]# cat /etc/passwd | grep -E -o "\<[0-9]\>|\<[1-9][0-9]\>" 
0
0
1
1
2
2
3
4
4
7
5
0
6
0
7
0
8
12
10
14
11
0
12
13
30
14
50
99
99
81
81
69
69
32
32
29
29
68
68
42
42
38
38
48
48
76
89
89
74
74
72
72

10、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;

[root@zf ~]# cat /boot/grub/grub.conf | grep -E "^[[:space:]]+[[:alnum:]]+"   
root (hd0,0)    
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=UUID=10c8f38a-aa7e-44ba-81e2-bddbb6689b7c rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet 
initrd /initramfs-2.6.32-431.el6.x86_64.img

11、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;

  [root@zf ~]# cat /etc/rc.d/rc.sysinit | grep -E "^#[[:space:]]+[^[:space:]]+"       
    # /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)
    # Configure kernel parameters
    # Set the hostname.
    # Sync waiting for storage.
    # Device mapper & related initialization
    # Start any MD RAID arrays that haven't been started yet
    # Remount the root filesystem read-write.
    # Clean up SELinux labels
    # If relabeling, relabel mount points.
    # Mount all other filesystems (except for NFS and /proc, which is already
    # mounted). Contrary to standard usage,
    # filesystems are NOT unmounted in single user mode.
    # The 'no' applies to all listed filesystem types. See mount(8).
    # Update quotas if necessary
    # Check to see if a full relabel is needed
    # Initialize pseudo-random number generator
    # Configure machine if necessary.
    # Clean out /.
    # Do we need (w|u)tmpx files? We don't set them up, but the sysadmin might...
    # Clean up /var.
    # Clean up utmp/wtmp
    # Clean up various /tmp bits
    # Make ICE directory
    # Start up swapping.
    # Set up binfmt_misc
    # Boot time profiles. Yes, this should be somewhere else.
    # Now that we have all of our basic modules loaded and the kernel going,
    # let's dump the syslog ring somewhere so we can find it later
    # create the crash indicator flag to warn on crashes, offer fsck with timeout
    # Let rhgb know that we're leaving rc.sysinit

12、打出netstat -tan命令執行結果中以‘LISTEN’,后或跟空白字符結尾的行;

[root@zf ~]# netstat -tan | grep -E "LISTEN[[:space:]]*$"
tcp        0      0 0.0.0.0:60812               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 0.0.0.0:10050               0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      
tcp        0      0 :::111                      :::*                        LISTEN      
tcp        0      0 :::39216                    :::*                        LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN      
tcp        0      0 :::3306                     :::*                        LISTEN

13、添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息;

[root@zf ~]# useradd bash
[root@zf ~]# useradd testbash
[root@zf ~]# useradd basher
[root@zf ~]# useradd -s /sbin/nologin nologin

[root@zf ~]# shell=$(grep "basher" /etc/passwd | cut -d: -f7)
[root@zf ~]# grep "$shell"  /etc/passwd | cut -d: -f1  
root
aa
mageia
openstack
hadoop
bash
testbash
basher

14、顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用三種方式;

[root@zf ~]# grep  "^[sS].*" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097144 kB
SwapFree:        2097144 kB
Shmem:               432 kB
Slab:              99732 kB
SReclaimable:      42004 kB
SUnreclaim:        57728 kB 

[root@zf ~]# grep -E "^(s|S).*" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097144 kB
SwapFree:        2097144 kB
Shmem:               432 kB
Slab:              99720 kB
SReclaimable:      42000 kB
SUnreclaim:        57720 kB 

[root@zf ~]# grep -i "^s.*" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097144 kB
SwapFree:        2097144 kB
Shmem:               432 kB
Slab:              99808 kB
SReclaimable:      42060 kB
SUnreclaim:        57748 kB

15、顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶;

[root@zf ~]# grep -v "/sbin/nologin$" /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
aa
mageia
slackware
openstack
hadoop
bash
testbash
basher

16、顯示/etc/passwd文件中其默認shell為/bin/bash的用戶;

[root@zf ~]# grep  "/bin/bash$" /etc/passwd | cut -d: -f1           
root
aa
mageia
openstack
hadoop
bash
testbash
basherp

17、找出/etc/passwd文件中的一位數或兩位數;

[root@zf ~]# grep -E -o "\<[0-9]\>|\<[1-9][0-9]\>" /etc/passwd 
0
0
1
1
2
2
3
4
4
7
5
0
6
0
7
0
8
12
10
14
11
0
12
13
30
14
50
99
99
81
81
69
69
32
32
29
29
68
68
42
42
38
38
48
48
76
89
89
74
74
72
72

原創文章,作者:N25-深圳-尋覓,如若轉載,請注明出處:http://www.www58058.com/64396

(0)
N25-深圳-尋覓N25-深圳-尋覓
上一篇 2016-12-21 15:18
下一篇 2016-12-21 16:54

相關推薦

  • 你會用Python寫洗腦神曲嗎?

    Python實戰班-學員學習成果展示 同樣是周末,有些人是閑聊著度過,有些人是學習充電度過。 人與人最大的區別,是下班后的時間??茨阍趺慈ダ?。 周末時,馬哥Python實戰班的學員正在認真上課,他們中的不少人,月薪在10k以上,甚至月薪20k以上。 但他們沒有虛度周末時光。 #最浪費時間的就是:思而不學+猶豫不決。# 馬哥Python實戰班二期的小伙伴們才…

    Linux干貨 2016-07-05
  • 0805文本處理工具

    文本處理工具 查看文本文件     文件內容:less和cat            文件截?。篽ead和tail       &…

    Linux干貨 2016-08-07
  • linux分區管理工具—fdisk

    一、關于為什么要分區       (1)為了數據的安全:當文件系統只有一個分區時,如果遇到分區需要格式化的情況,則硬盤里的數據無法保留,而如果提前對硬盤做了分區那么就可以很好地額解決這個問題;       (2)為了提升效率:硬盤(這里單指機械硬盤)分為外圈和…

    Linux干貨 2016-03-12
  • wordpress和discuz的負載均衡(lvs-dr)

    wordpress和discuz的負載均衡 實驗目的:利用lvs-dr模型實現wordpress和discuz的負載均衡 實驗要求:客戶端訪問wordpress或discuz服務器時,無論被調度至哪臺RS上,其會話和訪問的頁面都應保持一致; 實驗環境:一臺server用作VS,兩臺server用作RS,一臺server用于部署mysql、NFS、wordpr…

    2017-05-13
  • 14 用戶組和權限管理4

    14 用戶組和權限管理4 一、雜項知識整理 1、groups 查看用戶所屬組列表 [user1@localhost ~]$ groups user3 user1 2、文件屬性:-rw-r–r–. 1 root root 0 8月   3 07:56 cgroup.clone_children &…

    Linux干貨 2016-08-04
  • 計算機的組成和其功能

    圖:計算機組成架構 計算機由硬件和軟件組成 硬件部分: CPU:又稱中央處理器,整個系統最高執行單元,執行各種運算,控制電腦自動協調地完成各種操作。 主板:它把計算機的各個部件緊密的連接在一起,各個部件通過主板進行數據傳輸,計算機重要的“交通樞紐”都在主板上,他的工作穩定性影響整機的工作穩定性。因同CPU的插腳和性能不同,所以針對不同的CPU也有不同的主板。…

    Linux干貨 2016-08-08

評論列表(1條)

  • 馬哥教育
    馬哥教育 2017-01-03 17:10

    正則表達式很容易將人的水平區分開來,作業中完成的很不錯,再接再勵。

欧美性久久久久