第四周作業—用戶權限管理和正則表達式練習

權限管理、正則表達式練習

1. 復制/etc/skel目錄為/home/tuser1,要求 /home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。
[root@localhost ~]# cp -R /etc/skel /home/tuser1
[root@localhost ~]# ls -ld /home/tuser1
drwxr-xr-x. 4 root root 4096 5月 21 05:09 /home/tuser1
[root@localhost ~]# chmod -R go=— /home/tuser1
[root@localhost ~]# ls -ld /home/tuser1
drwx——. 4 root root 4096 5月 21 05:09 /home/tuser1
2. 編輯 /etc/group 文件,添加組 hadoop。
[root@localhost ~]# vim /etc/group
在最后一行添加: hadoop:x:2008:
[root@localhost ~]# grep “hadoop” /etc/group
hadoop:x:2008:
3. 手動編輯 /etc/passwd 文件,新增一行,添加用戶 hadoop,其基本組ID為hadoop組的id號;其家目錄為 /home/hadoop。
[root@localhost ~]# vim /etc/passwd
[root@localhost ~]# tail -1 /etc/passwd
hadoop:x:2008:2008::/home/hadoop:
4. 復制 /etc/skel目錄為 /home/hadoop,要求修改 hadoop 目錄的屬組和其它用戶沒有任何訪問權限。
[root@localhost ~]# cp -r /etc/skel /home/hadoop
[root@localhost ~]# ls -ld /home/hadoop
drwxr-xr-x. 4 root root 4096 5月 21 05:24 /home/hadoop
[root@localhost ~]# chmod -R go=— /home/hadoop
[root@localhost ~]# ls -ld /home/hadoop
drwx——. 4 root root 4096 5月 21 05:24 /home/hadoop
[root@localhost ~]# id hadoop
uid=2008(hadoop) gid=2008(hadoop) 組=2008(hadoop)
5. 修改 /home/hadoop 目錄及其內部所有文件的屬主為 hadoop,屬組為hadoop。
[root@localhost ~]# ls -ld /home/hadoop
drwx——. 4 root root 4096 5月 21 05:24 /home/hadoop
[root@localhost ~]# chown -R hadoop:hadoop /home/hadoop
[root@localhost ~]# ls -la /home/hadoop
總用量 28
drwx——. 4 hadoop hadoop 4096 5月 21 05:24 .
drwxr-xr-x. 14 root root 4096 5月 21 05:24 ..
-rw——-. 1 hadoop hadoop 18 5月 21 05:24 .bash_logout
-rw——-. 1 hadoop hadoop 176 5月 21 05:24 .bash_profile
-rw——-. 1 hadoop hadoop 124 5月 21 05:24 .bashrc
drwx——. 2 hadoop hadoop 4096 5月 21 05:24 .gnome2
drwx——. 4 hadoop hadoop 4096 5月 21 05:24 .mozilla
6. 顯示 /proc/meminfo 文件中以大寫或小寫s開頭的行;用兩種方式;
方法1:
[root@localhost ~]# grep -i “^s.*” /proc/meminfo
SwapCached: 8 kB
SwapTotal: 3157400 kB
SwapFree: 3157392 kB
Shmem: 4604 kB
Slab: 110976 kB
SReclaimable: 41000 kB
SUnreclaim: 69976 kB
方法2:
[root@localhost ~]# grep “^[sS].*” /proc/meminfo
SwapCached: 8 kB
SwapTotal: 3157400 kB
SwapFree: 3157392 kB
Shmem: 4604 kB
Slab: 110940 kB
SReclaimable: 41004 kB
SUnreclaim: 69936 kB
方法3:
[root@localhost ~]# grep -E “^(s|S).*” /proc/meminfo
SwapCached: 8 kB
SwapTotal: 3157400 kB
SwapFree: 3157392 kB
Shmem: 4604 kB
Slab: 110916 kB
SReclaimable: 40996 kB
SUnreclaim: 69920 kB
7. 顯示 /etc/passwd 文件中其默認shell為非 /sbin/nologin 的用戶;
[root@localhost ~]# 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
centos:x:500:500::/home/centos:/bin/bash
fedora:x:501:501::/home/fedora:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016::/home/slackware:/bin/tcsh
user1:x:2003:2003::/home/user1:/bin/bash
user2:x:2004:2004::/home/user2:/bin/bash
user3:x:2005:2005::/home/user3:/bin/bash
a1:x:2006:2006::/home/a1:/bin/bash
a2:x:2007:2007::/home/a2:/bin/bash
hadoop:x:2008:2008::/home/hadoop:
[root@localhost ~]# grep -v “/sbin/nologin$” /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
centos
fedora
mageia
slackware
user1
user2
user3
a1
a2
hadoop
bash
testbash
basher
8. 顯示/etc/passwd 文件中其默認shell為 /bin/bash的用戶;
[root@localhost ~]#
[root@localhost ~]# grep “/bin/bash$” /etc/passwd
root:x:0:0:root:/root:/bin/bash
centos:x:500:500::/home/centos:/bin/bash
fedora:x:501:501::/home/fedora:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
user1:x:2003:2003::/home/user1:/bin/bash
user2:x:2004:2004::/home/user2:/bin/bash
user3:x:2005:2005::/home/user3:/bin/bash
a1:x:2006:2006::/home/a1:/bin/bash
a2:x:2007:2007::/home/a2:/bin/bash
[root@localhost ~]# grep “/bin/bash$” /etc/passwd | cut -d: -f1
root
centos
fedora
mageia
user1
user2
user3
a1
a2
9. 找出 /etc/passwd 文件中的一位數或兩位數;
[root@localhost ~]# grep -E “\<[0-9]{1,2}\>” /etc/passwd –color=auto
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
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/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
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
saslauth:x:498:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/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 中以至少一個空白字符開頭的行;
[root@localhost ~]# grep -E “^[[:space:]]+” /boot/grub/grub.conf
11. 顯示 /etc/rc.d/rc.sysinit 文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;
[root@localhost ~]# grep -E “^#[[:space:]]+[^[:space:]]+” /etc/rc.d/rc.sysinit
12. 打出 netstat -tan 命令執行結果中以 ‘LISTEN’ ,后或跟空白字符結尾的行;
[root@localhost ~]# netstat -tan | grep “LISTEN[[:space:]]*$”
13. 添加用戶bash,testbash,basher,nologin(此用戶的shell為 /sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的信息;
[root@localhost ~]# useradd bash
[root@localhost ~]# useradd testbash
[root@localhost ~]# useradd basher
[root@localhost ~]# useradd nologin -s /sbin/nologin
[root@localhost ~]# tail -4 /etc/passwd
bash:x:2009:2009::/home/bash:/bin/bash
testbash:x:2010:2010::/home/testbash:/bin/bash
basher:x:2011:2011::/home/basher:/bin/bash
nologin:x:2012:2012::/home/nologin:/sbin/nologin
[root@localhost ~]# grep -E “(^[^:]+).*\1$” /etc/passwd -o
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
nobody:x:99:99:Nobody:/:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
bash:x:2009:2009::/home/bash:/bin/bash
basher:x:2011:2011::/home/basher:/bin/bash
nologin:x:2012:2012::/home/nologin:/sbin/nologin

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

(0)
allanallan
上一篇 2018-05-31
下一篇 2018-06-01

相關推薦

  • 計算機原理與Linux基礎

    計算機的組成及功能 1、其實計算機的組織分為內部設備和外部設備, 內部設備: ? ? ? ? CPU:運算器、寄存器、緩存 ? ? ? ? 存儲器:內存,RAM(Random Access Memory) ? ? ? ? 控制器:控制器是整個計算機系統的控制中心,它指揮計算機各部分協調地工作,保證計算機按照預先規定的目標和步驟有條不紊地進行操作及處理。 外部…

    Linux筆記 2018-05-13
  • keepalived之ipvs-dr

    keepalived初試

    2018-07-15
  • Linux的哲學思想

    Linux的哲學思想 1、一切皆文件(硬件設備亦如此): 所有資源在Linux上都已以文件方式存在,包括硬件設備(設備文件)通信接口。 linux 系統中所有的設備都是作為文件系統的一個節點來掛載和使用的,比如光驅,一般掛載在 /mnt/ cdrom 里,cpu掛載在/dev/cpu. 2、 由眾多功能單一的小程序組成: 且每一個小程序只做一件事情,并且只做…

    Linux筆記 2018-08-04
  • fstab、init文件創建,內核啟動管理

    /etc/下的fstab文件和/sbin/下的init文件的創建,內核啟動列表管理簡述

    2018-05-15
  • Linux進程監控管理工具詳解

    在上一節我們介紹了一些常用進程管理命令用法,但在實際生產環境運用時,我們可能需要動態持續的監控進程的運行狀態,此時我們就需要top,htop,iotop、glances等命令工具來實現。

    2018-05-05
  • 在linux服務器上運行django項目

    在linux服務器上運行django項目(1)需進入已創建的虛擬環境中。 (2)在虛擬環境中進入需要運行django項目(需進入到含有apps等文件的文件夾)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?進入哪個虛擬環境就是用哪個虛擬環境。 (3)MAKEMIGRATIONS:命令 python man…

    Linux筆記 2018-05-01

評論列表(1條)

  • 馬哥教育
    馬哥教育 2018-06-06 10:43

    寫的很好,可以用來當范文展示了

欧美性久久久久