N25第四周總結

linux bassic Week 4 Blogging

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

~]# cp -r /etc/skel/   /home/tuser1/
~]# chmod -R g-rwx,o-rwx /home/tuser1/
~]# ls -la /home/tuser1/
total 28
d---------. 4 root root 4096 Dec 20 10:56 .
drwxr-xr-x. 6 root root 4096 Dec 20 10:19 .. 注意此文件位當前目錄上一級目錄
----------. 1 root root   18 Dec 20 10:19 .bash_logout
----------. 1 root root  176 Dec 20 10:19 .bash_profile
----------. 1 root root  124 Dec 20 10:19 .bashrc
d---------. 2 root root 4096 Dec 20 10:19 .gnome2
drwx------. 3 root root 4096 Dec 20 10:56 skel

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

~]# vim /etc/group
distro:x:5000:
peguin:x:5001:
gentoo:x:3002:
fedora:x:3003:
mageedu:x:5010:gentoo,fedora
fed:x:3004:
gentoo1:x:3005:
gentoo2:x:3006:
hadoop:x:3008:  編輯添加,G-->o在尾行添加

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

~]# vim /etc/passwd
gentoo1:x:3005:3005::/users/gentoo1:/bin/bash
gentoo2:x:3006:3006::/users/gentoo:/bin/bash
gen:x:3007:3007::/users/gen:/bin/bash
hadoop:x:3008:3008::/home/hadoop:/bin/bash

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

~]# cp -r /etc/skel/ /home/hadoop
~]# chmod g-rwx,o-rwx /home/hadoop/
 ~]# ls -la /home/hadoop/
total 24
drwx------. 3 root root 4096 Dec 20 11:10 .
drwxr-xr-x. 7 root root 4096 Dec 20 11:10 ..
-rw-r--r--. 1 root root   18 Dec 20 11:10 .bash_logout
-rw-r--r--. 1 root root  176 Dec 20 11:10 .bash_profile
-rw-r--r--. 1 root root  124 Dec 20 11:10 .bashrc
drwxr-xr-x. 2 root root 4096 Dec 20 11:10 .gnome2

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

~]# chown -R  hadoop:hadoop /home/hadoop/
~]# ls -la /home/hadoop/
total 24
drwx------. 3 hadoop hadoop 4096 Dec 20 11:10 .
drwxr-xr-x. 7 root   root   4096 Dec 20 11:10 .. 當前目錄的上一級目錄
-rw-r--r--. 1 hadoop hadoop   18 Dec 20 11:10 .bash_logout
-rw-r--r--. 1 hadoop hadoop  176 Dec 20 11:10 .bash_profile
-rw-r--r--. 1 hadoop hadoop  124 Dec 20 11:10 .bashrc
drwxr-xr-x. 2 hadoop hadoop 4096 Dec 20 11:10 .gnome2

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

~]# grep "^[sS]" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:               232 kB
Slab:              66492 kB
SReclaimable:      11380 kB
SUnreclaim:        55112 kB
~]# grep "^(s|S)" /proc/meminfo  第二種方法
 ~]# grep -i "^s" /proc/meminfo  第三種方法

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

~]# 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
openstack:x:3000:3000::/home/openstack:/bin/bash
archinux:x:3001:3001::/home/archinux:/bin/bash
gentoo:x:3002:3002::/users/gentoo:/bin/bash
fedora:x:3003:3003::/users/fedora:/bin/bash
fed:x:3004:3004::/users/fed:/bin/bash
gentoo1:x:3005:3005::/users/gentoo1:/bin/bash
gentoo2:x:3006:3006::/users/gentoo:/bin/bash
gen:x:3007:3007::/users/gen:/bin/bash
hadoop:x:3008:3008::/home/hadoop:/bin/bash
~]# grep -v "/sbin/nologin$" /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
openstack
archinux
gentoo
fedora
fed
gentoo1
gentoo2
gen
hadoop

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

 ~]# grep "/bin/bash" /etc/passwd | cut -d: -f1rootopenstackarchinuxgentoofedorafedgentoo1gentoo2genhadoop

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

~]# grep -o "[0-9][0-9]\>" /etc/passwd   這是是錯誤的,默認工作在貪婪模式包含里面數字都匹配
12
10
14
11
12
00
13
30
14
50
99
99
81
81
69
69
73
73
68
68
38
38
99
76
89
89
74
74
72
72
00
00
01
01
02
02
03
03
04
04
05
~]# grep -E -o "\<[0-9]{1,2}\>" /etc/passwd 必須錨定詞首詞尾

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

~]# grep -E "^[[:space:]]+" /boot/grub/grub.conf 
~]# grep -E "^[[:space:]]+" /boot/grub/grub.conf 
root (hd0,0)
kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=cae1b7e9-d579-46d0-9723-51391a99e07f rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-504.el6.x86_64.img

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

~]# grep -E -o "^[[:space:]]+" /boot/grub/grub.conf 		
[root@mytest6 ~]# grep -E "^#[[:space:]]+[^[:space:]]" /etc/rc.d/rc.sysinit 
# /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.
......

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

~]# netstat -tan | grep  "LISTEN[[:space:]]*$"
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN

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

 ~]# grep -E -o  "^([^:]+\>).*\1$" /etc/passwd

原創文章,作者:讓優秀稱為一種習慣,如若轉載,請注明出處:http://www.www58058.com/64713

(0)
讓優秀稱為一種習慣讓優秀稱為一種習慣
上一篇 2016-12-26
下一篇 2016-12-26

相關推薦

  • 建立yum源及yum命令的使用

    一、什么是YUM     YUM的全稱為 Yellowdog Update Modifier,其主要目的是為了解決RPM包安裝時的依賴關系的問題。YUM只是一個用于軟件安裝的前端工具,其主要的服務對象還是RPM軟件包。     YUM采用C/S架構,即客戶端與服務器的?!?/p>

    Linux干貨 2015-05-11
  • gzip壓縮輸出

    一、gzip介紹          gzip是GNU zip的縮寫,它是一個GNU自由軟件的文件壓縮程序,也經常用來表示gzip這種文件格式。軟件的作者是Jean-loup Gailly和Mark Adler。1992年10月31日第一次公開發布,版本號是0.1,目前的穩定版本是…

    Linux干貨 2015-07-29
  • 文本處理工具初探

    作為一個系統管理員,文本處理功能是經常使用的,熟練地使用各種文本工具有助于提高工作效率,從繁忙的工作中早點解脫。下面就來介紹處理文本的常用命令。 處理文本的命令大致分為:        查看文件內容:cat、less、more       …

    Linux干貨 2016-08-07
  • 軟件包管理(rpm篇)

    軟件包管理(rpm篇)靜態和動態鏈接    鏈接主要作用是把各個模塊之間相互引用的部分處理好,使得各個模塊之間能夠正確地銜接,分為靜態鏈接和動態鏈接    靜態鏈接        把程序對應的依賴庫復制一份到包&nbsp…

    Linux干貨 2017-04-24
  • DNS服務

    名字解析,DNS服務,實現主從服務器,實現子域

    2018-01-22
  • MBR與GPT分區結構的不同及磁盤分區命令總結

    一、MBR分區結構 主引導記錄(Master Boot Record,縮寫:MBR),又叫做主引導扇區,是目前比較流行的一種分區結構。磁盤的0磁道0扇區稱為MBR,它的大小是512字節,這個區域被分為三個部分: 第一部分為boot loader(主引導程序),占446字節; 第二部分為Partition table(分區表),即DPT,占64字節,每個分區項…

    Linux干貨 2016-08-29

評論列表(1條)

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

    掌握的不錯,相信正則表達式會對你今后的工作起到很大的益處。

欧美性久久久久