集中練習2

用戶管理、文本處理、文件管理相關

(1) 復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其他用戶均沒有任何訪問權限。
“`
~]# cp -r /etc/skel /home/tuser1
~]# touch /home/tuser1/{a,b,c}
~]# mkdir /home/tuser1/abc/db/dc -pv
~]# tree /home/tuser1
/home/tuser1
├── a
├── abc
│ └── db
│ └── dc
├── b
└── c
~]# ll /home/tuser1
total 0
-rw——-. 1 root root 0 Sep 19 19:13 a
drwx——. 3 root root 16 Sep 19 19:12 abc
-rw——-. 1 root root 0 Sep 19 19:13 b
-rw——-. 1 root root 0 Sep 19 19:13 c
~]# ls -ld /home/tuser1
drwx——. 4 root root 116 Sep 19 19:13 /home/tuser1
“`
(2) 編輯/etc/group文件,添加組hadoop。
“`
~]# vim /etc/group
在文件末尾添加一行:hadoop:x:1008:
~]# tail -1 /etc/group
hadoop:x:1008:
“`
(3) 手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop。
“`
~]# vim /etc/passwd
在文件末尾添加一行:hadoop:x:1008:1008::/home/hadoop:/bin/bash
~]# tail -1 /etc/passwd
hadoop:x:1008:1008::/home/hadoop:/bin/bash
“`
(4) 復制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其他用戶沒有任何訪問權限。
“`
~]# cp -r /etc/skel /home/hadoop
~]# chmod go-rwx /home/hadoop
~]# ls -ld /home/hadoop
drwx——. 3 root root 78 Sep 19 19:23 /home/hadoop
“`
(5) 修改/home/hadoop目錄及其內部所有文件的屬主為hadoop,屬組為hadoop。
“`
~]# mkdir /home/hadoop/test
~]# touch /home/hadoop/test/{a,b,c,d}
~]# tree /home/hadoop
/home/hadoop
└── test
├── a
├── b
├── c
└── d
~]# chown -R hadoop:hadoop /home/hadoop
~]# ls -ld /home/hadoop
drwx——. 4 hadoop hadoop 90 Sep 19 19:28 /home/hadoop
~]# ll /home/hadoop/test/
total 0
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 a
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 b
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 c
-rw-r–r–. 1 hadoop hadoop 0 Sep 19 19:28 d
“`
(6) 顯示/proc/meminfo文件中以答謝或小寫s開頭的行;用兩種方式。
“`
方法1:~]# grep -i “^s” /proc/meminfo
方法2:~]# grep -E “^(s|S)” /proc/meminfo
方法3:~]# grep “^[s,S]” /proc/meminfo
“`
(7) 顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶。
“`
~]# grep -v “/sbin/nologin$” /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
sapbcs
openstack
mariadb
gentoo
fedora
centos
tom
jerry
neo
hadoop
“`
(8) 顯示/etc/passwd文件中其默認shell為/bin/bash的用戶。
“`
~]# grep “/bin/bash$” /etc/passwd | cut -d: -f1
root
sapbcs
openstack
gentoo
fedora
centos
tom
jerry
neo
hadoop
“`
(9) 找出/etc/passwd文件中的一位數或兩位數。
“`
~]# grep -E “\<[0-9]\>|\<[1-9][0-9]\>” /etc/passwd
“`
(10) 顯示/boot/grub/grub.conf中至少一個空白字符開頭的行。
“`
CentOS7沒有題中的文件,我換了一個文件。
~]# grep -E “^[[:space:]]+” /boot/grub2/grub.cfg
“`
(11) 顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行。
“`
CentOS7中沒有題中的文件,我換了一個文件
~]# 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命令執行結果中以’LISTEN’,后或跟空白字符結尾的行。
“`
~]# netstat -tan | grep -E “LISTEN[[:space:]]+”
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
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 :::111 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
“`
(13) 添加用戶bash,testbash,basher,nologin(此一用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息。
“`
~]# useradd bash
~]# useradd testbash
~]# useradd basher
~]# useradd nologin -s /sbin/nologin
~]# grep -E “^(\<[[:alpha:]]+[^:]\>).*\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:1009:1009::/home/bash:/bin/bash
nologin:x:1012:1012::/home/nologin:/sbin/nologin
“`

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/87470

(0)
N27_sapbcsN27_sapbcs
上一篇 2017-09-20 17:49
下一篇 2017-09-20 17:51

相關推薦

  • 第10周作業(下)

    4、寫一個腳本(1) 能接受四個參數:start, stop, restart, statusstart: 輸出“starting 腳本名 finished.”(2) 其它任意參數,均報錯退出。 #!/bin/bash # [ $# -ne 1 ] && echo &quo…

    Linux干貨 2017-01-03
  • 第四周作業

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。[root@localhost ~]# cp -r /etc/skel/ /home/tuser1[root@localhost /]# chmod -R g=,o= /home/tuser1 2、編輯/etc/group文件…

    Linux干貨 2017-03-04
  • 初識MySQL(二)SQL語句

        MySQL是關系型數據庫的一種,基于二維表實現數據的存儲與讀取,通過索引實現快速查詢,而實現數據庫、表、索引的操作則是由SQL語句來完成的。     1、MySQL中字符大小寫       (1)、SQL關鍵字以及函數名不…

    Linux干貨 2015-08-26
  • 第一周的學習總結

       本人是Linux 小白,0基礎。加入馬幫開始Linux之旅。由于完全不懂Linux,所以在學習的過程中,每課都要看上2遍。接下來說說我第一周所學的內容。 首先是了解到了計算機基礎知識,計算機的組成部分、CPU架構類型、其他外圍設備。 操作系統基礎知識進程管理、內存管理、網絡管理、驅動管理、安全管理等。 Linux的起源、發行版以及構…

    Linux干貨 2016-02-28
  • Linux主要發行版

    Redhat:三大發行版之一,由紅帽公司維護,分支有fedora,centosDebian:社區維護,非商業維護,三大發行版之一,分支有Ubuntu,Mintslackware:三大發行版之一,分支有Suse,opensusearch Linux:輕量級行業新貴

    Linux干貨 2018-03-03
  • 馬哥教育網絡班22期+第2周課程練習

    1、  Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。 cp命令 單源復制:cp [OPTION]… [-T] SOURCE DEST 多源復制:cp [OPTION]… SOURCE… DIRECTORY 多源復制:cp [OPTION]… -t DIRECTORY SOU…

    Linux干貨 2016-08-22
欧美性久久久久