Linux第四周作業

Linux

1、 復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。
~]# cp /etc/skel/ /home/tuser1
home]# getfacl tuser1/
# file: tuser1/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
home]# setfacl -m u::7,g::0,o::0 tuser1/
[root@ada-dog home]# getfacl tuser1/
# file: tuser1/
# owner: root
# group: root
user::rwx
group::—
other::—

2、 編輯/etc/group文件,添加組hadoop。
~]# echo “hadoop:x:1004:” >> /etc/group
3、 手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop。
~]# echo “hadoop:x:1003:1004::/home/hadoop:/bin/bash” >> /etc/passwd
4、 復制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒有任何訪問權限。
home]# cp -rv /etc/skel/ /home/hadoop/
“/etc/skel/” -> “/home/hadoop/”
“/etc/skel/.mozilla” -> “/home/hadoop/.mozilla”
“/etc/skel/.mozilla/extensions” -> “/home/hadoop/.mozilla/extensions”
“/etc/skel/.mozilla/plugins” -> “/home/hadoop/.mozilla/plugins”
“/etc/skel/.bash_logout” -> “/home/hadoop/.bash_logout”
“/etc/skel/.bash_profile” -> “/home/hadoop/.bash_profile”
“/etc/skel/.bashrc” -> “/home/hadoop/.bashrc”
[root@ada-dog home]# getfacl hadoop/
# file: hadoop/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
home]# setfacl -m u::7,g::0,o::0 hadoop/
[root@ada-dog home]# getfacl hadoop/
# file: hadoop/
# owner: root
# group: root
user::rwx
group::—
other::—

5、 修改/home/hadoop目錄及其內部所有文件的屬主為hadoop,屬組為hadoop。
home]# chown -Rv hadoop:hadoop /home/hadoop/
changed ownership of “/home/hadoop/.mozilla/extensions” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.mozilla/plugins” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.mozilla” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.bash_logout” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.bash_profile” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/.bashrc” from root:root to hadoop:hadoop
changed ownership of “/home/hadoop/” from root:root to hadoop:hadoop
home]# ls -al /home/hadoop/
總用量 12
drwx——. 3 hadoop hadoop 78 7月 10 15:41 .
drwxr-xr-x. 7 root root 73 7月 10 15:41 ..
-rw-r–r–. 1 hadoop hadoop 18 7月 10 15:41 .bash_logout
-rw-r–r–. 1 hadoop hadoop 193 7月 10 15:41 .bash_profile
-rw-r–r–. 1 hadoop hadoop 231 7月 10 15:41 .bashrc
drwxr-xr-x. 4 hadoop hadoop 39 7月 10 15:41 .mozilla
6、 顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用兩種方式;
~]# grep -i ‘^s’ /proc/meminfo
SwapCached: 1456 kB
SwapTotal: 3145724 kB
SwapFree: 3112296 kB
Shmem: 2252 kB
Slab: 57744 kB
SReclaimable: 19724 kB
SUnreclaim: 38020 kB
~]# grep -E ‘^[sS]’ /proc/meminfo
SwapCached: 1652 kB
SwapTotal: 3145724 kB
SwapFree: 3111748 kB
Shmem: 2216 kB
Slab: 57168 kB
SReclaimable: 19724 kB
SUnreclaim: 37444 kB

7、 顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶;
~]# cat /etc/passwd | grep -v “/sbin/nologin” | cut -d: -f1
root
sync
shutdown
halt
ada
fedora
centos
hadoop
8、 顯示/etc/passwd文件中其默認shell為/bin/bash的用戶;
~]# cat /etc/passwd | grep “/bin/bash” | cut -d: -f1
root
ada
fedora
centos
hadoop

9、 找出/etc/passwd文件中的一位數或兩位數;
~]# grep “\<[[:digit:]]\{,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
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
10、 顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;
~]# grep “^[[:space:]]\+” /boot/grub/grub.conf
dfsgs
safa
gsgsg
wsd
sdfdse444
esg
fsgr\
11、 顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;
~]# grep “^#[[:space:]]\+[^[:space:]]\+” /etc/rc.d/rc.sysinit
# It receives polydir path as $1, the instance path as $2,
# a flag whether the instance dir was newly created (0 – no, 1 – yes) in $3,
# and user name in $4.
# The following section will copy the contents of /etc/skel if this is a
# newly created home directory.

12、 打出netstat -tan命令執行結果中以‘LISTEN’,后或跟空白字符結尾的行;
~]# netstat -tan | grep “LISTEN[[:space:]]\+”
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 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:6011 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
tcp6 0 0 ::1:6010 :::* LISTEN
tcp6 0 0 ::1:6011 :::* LISTEN

13、 添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息;
~]# useradd bash
~]# useradd testbash
~]# useradd basher
~]# useradd -s /sbin/nologin nologin
~]# grep “^\([^:]\+\>\).*\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:501:501::/home/bash:/bin/bash
nologin:x:504:504::/home/nologin:/sbin/nologin

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

(0)
FelixFelix
上一篇 2018-07-14 16:28
下一篇 2018-07-14 19:26

相關推薦

  • 兩臺主機之間搭建路由通信

    搭建路由通信

    2018-04-29
  • linux第三周小結

    本周小結內容包括shell腳本基礎知識、文件查找命令locate和find、文本處理工具sed

    Linux筆記 2018-04-15
  • Linux中的文本查看和處理練習題

    linux中的文本查看和處理練習題
    linux用戶和組管理類命令的使用方法及練習

    Linux筆記 2018-07-08
  • K8S的安裝

    使用kubeadm安裝部署kubernetes集群: 前提:1、各節點時間同步;2、各節點主機名稱解析:dns OR hosts;3、各節點iptables及firewalld服務被disable; 一、設置主節點安裝程序包 1、生成yum倉庫配置: 主管理節點上的yum倉庫的配置: 先配置安裝docker倉庫: [docker]name=dockerbas…

    2018-08-08
  • Linux第六周作業

    1、簡述osi七層模型和TCP/IP五層模型   2、簡述iproute家族命令   3、詳細說明進行管理工具htop、vmstat等相關命令,并舉例   4、使用until和while分別實現192.168.0.0/24網段內,地址是否能夠ping通,弱ping通則輸出”success!”,若ping不…

    2018-08-06
  • ansible進階小技巧

    用ansible寫playbook的朋友可能會發現,當配置工作很多時,如果在中間過程出錯了,修改后想重新執行,前面的一大堆步驟讓人感覺很煩躁。雖然提供了“retry”文件,但是卻只是根據host來判斷重新執行,仍然不夠方便;又或者,中間的某些步驟特別耗時,比如下載一個很大的數據包,每次執行特別浪費時間,想要特別的跳過。怎么辦?我猜你就是把不需要的部分給注釋掉…

    Linux筆記 2018-06-03
欧美性久久久久