N25 – Week 4 blog

第四周博客作業了,感覺前面的有好多都忘掉了,但是沒有時間補以前的啊……好郁悶,幸好今天周五,明天又是圣誕節,從馬云爸爸買了一顆圣誕樹,今晚回家裝上N25 - Week 4 blog

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

[root@dhcp-10-129-6-166 ~]# install -d -m u=rwx,go= /etc/skel /home/tuser1;ll -d /home/tuser1
drwx------. 2 root root 6 12月 23 14:09 /home/tuser1
[root@dhcp-10-129-6-166 ~]#

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

[root@dhcp-10-129-6-166 home]# echo "hadoop:x:3100:" >> /etc/group
[root@dhcp-10-129-6-166 home]# tail -1 /etc/group
hadoop:x:3100:
[root@dhcp-10-129-6-166 home]#

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

[root@dhcp-10-129-6-166 home]# tail /etc/passwd
mysql:x:996:994::/home/mysql:/bin/nologin
mariadb:x:995:993::/home/mariadb:/sbin/nologin
gentoo:x:2004:2004::/users/gentoo:/bin/bash
fedora:x:2005:2005::/users/fedora:/bin/bash
centos:x:2006:2006::/home/centos:/bin/bash
bash:x:2007:2007::/home/bash:/bin/bash
testbash:x:2008:2008::/home/testbash:/bin/bash
basher:x:2009:2009::/home/basher:/bin/bash
nologin:x:2010:2010::/home/nologin:/sbin/nologin
Bash:x:3001:3001::/home/Bash:/bin/bash
[root@dhcp-10-129-6-166 home]# echo "hadoop:x:3100:3100::/home/hadoop:/bin/bash" >> /etc/passwd
[root@dhcp-10-129-6-166 home]# tail -1 /etc/passwd
hadoop:x:3100:3100::/home/hadoop:/bin/bash

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

[root@dhcp-10-129-6-166 home]# install -d -m go-rwx /etc/skel /home/hadoop
[root@dhcp-10-129-6-166 home]# ll -d /home/hadoop
drwx------. 2 root root 6 12月 23 13:54 /home/hadoop
[root@dhcp-10-129-6-166 home]#

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

[root@dhcp-10-129-6-166 home]# ll /home/hadoop
總用量 0
-rw-r--r--. 1 root root 0 12月 23 13:36 file1
-rw-r--r--. 1 root root 0 12月 23 13:36 file2
-rw-r--r--. 1 root root 0 12月 23 13:36 file3
-rw-r--r--. 1 root root 0 12月 23 13:36 file4
[root@dhcp-10-129-6-166 home]# chown -R hadoop:hadoop /home/hadoop;ll -r /home/hadoop
總用量 0
-rw-r--r--. 1 hadoop hadoop 0 12月 23 13:36 file4
-rw-r--r--. 1 hadoop hadoop 0 12月 23 13:36 file3
-rw-r--r--. 1 hadoop hadoop 0 12月 23 13:36 file2
-rw-r--r--. 1 hadoop hadoop 0 12月 23 13:36 file1
[root@dhcp-10-129-6-166 home]#

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

[root@dhcp-10-129-6-166 ~]# grep "^[sS]" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             13104 kB
Slab:              73684 kB
SReclaimable:      36116 kB
SUnreclaim:        37568 kB
[root@dhcp-10-129-6-166 ~]# grep "^(s|S)" /proc/meminfo
[root@dhcp-10-129-6-166 ~]# grep -E "^(s|S)" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             13104 kB
Slab:              73684 kB
SReclaimable:      36116 kB
SUnreclaim:        37568 kB

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

[root@dhcp-10-129-6-166 system]# 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
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016::/home/slackware:/bin/bash
openstack:x:2003:2020::/home/openstack:/bin/bash
mysql:x:996:994::/home/mysql:/bin/nologin
gentoo:x:2004:2004::/users/gentoo:/bin/bash
fedora:x:2005:2005::/users/fedora:/bin/bash
centos:x:2006:2006::/home/centos:/bin/bash
bash:x:2007:2007::/home/bash:/bin/bash
testbash:x:2008:2008::/home/testbash:/bin/bash
basher:x:2009:2009::/home/basher:/bin/bash
hadoop:x:3000:3000::/home/hadoop:/bin/bash
Bash:x:3001:3001::/home/Bash:/bin/bash

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

[root@dhcp-10-129-6-166 ~]# grep "/bin/bash$" /etc/passwd
root:x:0:0:root:/root:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016::/home/slackware:/bin/bash
openstack:x:2003:2020::/home/openstack:/bin/bash
gentoo:x:2004:2004::/users/gentoo:/bin/bash
fedora:x:2005:2005::/users/fedora:/bin/bash
centos:x:2006:2006::/home/centos:/bin/bash
bash:x:2007:2007::/home/bash:/bin/bash
testbash:x:2008:2008::/home/testbash:/bin/bash
basher:x:2009:2009::/home/basher:/bin/bash
hadoop:x:3000:3000::/home/hadoop:/bin/bash

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

[root@dhcp-10-129-6-166 ~]# grep -E -o "\<[0-9]\>|\<[0-9][0-9]\>" /etc/passwd
0
0
1
1
2
2
3
4
4
7
5
0
6
0
7
0
8
12
11
0
12
14
50
99
99
81
81
59
59
89
89
74
74
[root@dhcp-10-129-6-166 ~]#

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

[root@dhcp-10-129-6-166 ~]# grep "^[[:space:]]\+" /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
...

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

[root@dhcp-10-129-6-166 ~]# grep "^#[[:space:]][^[:space:]]" /etc/rc.d/rc.sysinit

12. 打出netstat -tan命令執行結果中以'LISTEN',后或根空白字符結尾的行

[root@dhcp-10-129-6-166 system]# netstat -tan | grep "\<LISTEN\>[[:space:]]\+$"
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(此一個用戶的shell為/sbin/nologin), 而后找出當前系統上其用戶名和默認shell相同的用戶的信息

[root@dhcp-10-129-6-166 system]# grep -E "^(\<[^:]+\>).*\<\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:2007:2007::/home/bash:/bin/bash
nologin:x:2010:2010::/home/nologin:/sbin/nologin

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

[root@dhcp-10-129-6-166 system]# grep "^[sS]" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             13104 kB
Slab:              73876 kB
SReclaimable:      36340 kB
SUnreclaim:        37536 kB
[root@dhcp-10-129-6-166 system]# grep -E "^(s|S)" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             13104 kB
Slab:              73876 kB
SReclaimable:      36340 kB
SUnreclaim:        37536 kB
[root@dhcp-10-129-6-166 system]# grep -i "^s" /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             13104 kB
Slab:              73876 kB
SReclaimable:      36340 kB
SUnreclaim:        37536 kB

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

[root@dhcp-10-129-6-166 system]# grep "/sbin/nologin$" /etc/passwd
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
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
systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
systemd-network:x:998:996:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:997:995:User for polkitd:/:/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
mariadb:x:995:993::/home/mariadb:/sbin/nologin
nologin:x:2010:2010::/home/nologin:/sbin/nologin

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

[root@dhcp-10-129-6-166 system]# grep "/bin/bash$" /etc/passwd
root:x:0:0:root:/root:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016::/home/slackware:/bin/bash
openstack:x:2003:2020::/home/openstack:/bin/bash
gentoo:x:2004:2004::/users/gentoo:/bin/bash
fedora:x:2005:2005::/users/fedora:/bin/bash
centos:x:2006:2006::/home/centos:/bin/bash
bash:x:2007:2007::/home/bash:/bin/bash
testbash:x:2008:2008::/home/testbash:/bin/bash
basher:x:2009:2009::/home/basher:/bin/bash
hadoop:x:3000:3000::/home/hadoop:/bin/bash
Bash:x:3001:3001::/home/Bash:/bin/bash

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

[root@dhcp-10-129-6-166 ~]# grep -E -o "\<[0-9]{1,2}\>" /etc/passwd
0
0
1
1
2
2
3
4
4
7
5
0
6
0
7
0
8
12
11
0
12
14
50
99
99
81
81
59
59
89
89
74
74
[root@dhcp-10-129-6-166 ~]#

原創文章,作者:JL,如若轉載,請注明出處:http://www.www58058.com/64267

(0)
JLJL
上一篇 2016-12-20 12:01
下一篇 2016-12-20 15:03

相關推薦

  • Linux systemd管理

                                                      &nbsp…

    系統運維 2016-09-28
  • grep與正則表達式

    文本處理中比較強悍的三個工具是:grep、sed、awk。 其中grep主要作用是對于用戶給出“模式”對文本逐行進行匹配檢查,然后進行打印。   模式:由正則表達式字符及文本字符編寫的過濾條件 格式:grep [選項] [正則表達式字符]  文件  常用的選項:     -v:反向查找,顯示沒有被匹配的的行 …

    Linux干貨 2016-08-08
  • 一起學DHCP系列(四)安裝、配置

    原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://jeffyyko.blog.51cto.com/28563/162580       本節將主要講述DHCP的安裝和配置。     …

    Linux干貨 2015-03-25
  • shell腳本語言中的選擇執行

    shell腳本語言中的選擇執行 概述 程序執行過程分為順序執行、選擇執行和循環執行。順序執行是指程序按照步驟一步一步地運行。選擇執行是指程序根據特定條件選擇兩項或者多項中的一項運行。循環執行是指程序根據特定條件重復執行直到某個節點結束,繼續運行其他步驟。本篇文章從判斷條件和條件判斷式簡要說明shell腳本語言中程序選擇執行的用法。 shell腳本中的判斷條件…

    Linux干貨 2017-04-17
  • 第十五周作業

    1、總結sed和awk的詳細用法; sed:     模式空間:sed是一種在線編輯器、行編輯器,一次處理一行內容,在處理時,把當前處理的行存儲在臨時緩沖區當中,并在該緩沖區中完成后續的處理,該緩沖區被稱為”模式空間”。     保持空間:在模式空間中處理完一行內容后會繼續處理下一行,但是對于處…

    Linux干貨 2017-04-18
欧美性久久久久