etc的常見問答

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

[root@localhost tuser1]# cp -r /etc/skel/ /home/tuser1
[root@localhost tuser1]# chmod -R go= /home/tuser1/
[root@localhost tuser1]# ll -d /home/tuser1/
drwx------. 2 root root 71 Dec 26 08:40 /home/tuser1/

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

[root@localhost tuser1]# echo "hadoop:x:2019:" >> /etc/group

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

[root@localhost tuser1]# echo "hadoop:x:2003:2019::/home/hadoop:/bin/bash" >> /etc/passwd
[root@localhost tuser1]# tail -2 /etc/passwd
slackware:x:2002:2016::/home/slackware:/bin/tcsh
hadoop:x:2003:2019::/home/hadoop:/bin/bash

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

[root@localhost tuser1]# cp -r /etc/skel/ /home/hadoop
[root@localhost tuser1]# chmod -R go= /home/hadoop/
[root@localhost tuser1]# ll -d /home/hadoop/
drwx------. 2 root root 71 Dec 26 08:42 /home/hadoop/

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

[root@localhost tuser1]# chown -R hadoop:hadoop /home/hadoop/
[root@localhost tuser1]# ll //home/hadoop/
total 0
-rw-------. 1 hadoop hadoop 0 Dec 26 08:42 1

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

[root@localhost tuser1]# cat /proc/meminfo |grep "^[sS]" 
SwapCached:            0 kB
SwapTotal:       9764860 kB
SwapFree:        9764860 kB
Shmem:              6860 kB
Slab:              62908 kB
SReclaimable:      23144 kB
SUnreclaim:        39764 kB
[root@localhost tuser1]# cat /proc/meminfo |grep -i "^s" 
SwapCached:            0 kB
SwapTotal:       9764860 kB
SwapFree:        9764860 kB
Shmem:              6860 kB
Slab:              62916 kB
SReclaimable:      23144 kB
SUnreclaim:        39772 kB

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

[root@localhost /]# cat /etc/passwd|grep -v "/bin/bash$"|cut -d: -f1|wc -l
21

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

[root@localhost /]# cat  /etc/passwd|grep "/bin/bash$" |cut -d: -f1
root
centos
mageia
hadoop
bash
testbash
basher

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

[root@localhost tuser1]# grep -o "\<[[:digit:]]\{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
89
89
74
74
48
48

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

[root@localhost /]# grep "^[[:space:]]\+" /boot/grub/gurb.conf

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

[root@localhost /]# cat /etc/rc.d/rc.sysinit |grep "^#[[:space:]]\+[^[:space:]]"

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

[root@localhost tuser1]# netstat -tan|grep "LISTEN[[:space:]]*$" |cat -E
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@localhost /]# cat /etc/passwd|egrep "^([^:]+\>).*\1$" 
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:2004:2004::/home/bash:/bin/bash
nologin:x:2007:2007::/home/nologin:/sbin/nologin

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

(1)
耗奇害死貓耗奇害死貓
上一篇 2017-12-26
下一篇 2017-12-28

相關推薦

  • 創建一個簡易的Linux

      目標:   為CentOS 6添加一塊新硬件,提供兩個主分區;    (1) 為硬盤新建兩個主分區;并為其安裝grub;    (2) 為硬盤的第一個主分區提供內核和ramdisk文件; 為第二個 分區提供rootfs;    (3) 為rootfs提供bash、ls、cat程序及所依賴的庫文件;    (4) 為grub提供配置文件;    …

    Linux干貨 2016-12-30
  • 第一周作業

    第一周作業 1、描述計算機的組成及其功能     計算機與操作系統:     CPU:運算器、控制器、寄存器、緩存     存儲器:內存,RAM(Random Access Memory)     Input:下指令,提供數據  …

    Linux干貨 2017-08-09
  • 22期第十三周課堂練習

    1、建立samba共享,共享目錄為/data,要求:(描述完整的過程)   1)共享名為shared,工作組為magedu;   2)添加組develop,添加用戶gentoo,centos和ubuntu,其中gentoo和centos以develop為附加組,ubuntu不屬于develop組;密碼均為用戶名;   3)添加s…

    Linux干貨 2017-01-09
  • 集中練習1-10個Linux運維腳本

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

    2017-09-20
  • PHP5.4的變化關注—What has changed in PHP 5.4.x

    What has changed in PHP 5.4.x Most improvements in PHP 5.4.x have no impact on existing code. There are a few incompatibilities and new features that should be …

    Linux干貨 2015-06-17
  • DNS服務和搭建

    DNS服務:        名字解析        DNS 服務        實現主從服務器        實現子域        實現view  …

    2017-04-16
欧美性久久久久