Linux權限管理練習

1、當用戶xiaoming對/testdir 目錄無執行權限時,意味著無法做哪些操作?

無法cd切換進入此目錄,無法創建文件,無法刪除文件,無法查看里面文件的內容,只能ls列出目錄下的內容

2、當用戶xiaoqiang對/testdir 目錄無讀權限時,意味著無法做哪些操作?

無法ls查看目錄下的內容

3、當用戶wangcai 對/testdir 目錄無寫權限時,該目錄下的只讀文件file1是否可修改和刪除?

無法修改也無法刪除

4、復制/etc/fstab文件到/var/tmp下,設置文件所有者為wangcai讀寫權限,所屬組為sysadmins組有讀寫權限,其他人無權限。

[root@localhost testdir]# cp /etc/fstab /var/tmp/
[root@localhost testdir]# chmod 660 /var/tmp/fstab 
[root@localhost testdir]# chown wangcai.sysadmins /var/tmp/fstab
[root@localhost testdir]# ll /var/tmp/fstab
-rw-rw----. 1 wangcai sysadmins 595 Aug  3 15:29 /var/tmp/fstab

5、誤刪除了用戶wangcai的家目錄,請重建并恢復該用戶家目錄及相應的權限屬性

[root@localhost ~]# cp -r /etc/skel/ /home/wangcai
[root@localhost ~]# chown -R wangcai.wangcai /home/wangcai
[root@localhost ~]# chmod 700 /home/wangcai
[root@localhost ~]# chmod 644 /home/wangcai/.bash
.bash_logout   .bash_profile  .bashrc        
[root@localhost ~]# chmod 644 /home/wangcai/.bash*
[root@localhost ~]# ll /home/wangcai/ -a
total 12
drwx------. 3 wangcai wangcai  74 Aug  3 15:31 .
drwxr-xr-x. 6 root    root     52 Aug  3 15:31 ..
-rw-r--r--. 1 wangcai wangcai  18 Aug  3 15:31 .bash_logout
-rw-r--r--. 1 wangcai wangcai 193 Aug  3 15:31 .bash_profile
-rw-r--r--. 1 wangcai wangcai 231 Aug  3 15:31 .bashrc
drwxr-xr-x. 4 wangcai wangcai  37 Aug  3 15:31 .mozilla

6、在/data/testdir里創建的新文件自動屬于g1組,組g2的成員如:alice能對這些新文件有讀寫權限,組g3的成員如:tom只能對新文件有讀權限,其它用戶(不屬于g1,g2,g3)不能訪問這個文件夾。

[root@localhost ~]# id alice
uid=1006(alice) gid=1010(alice) groups=1010(alice),1008(g2)
[root@localhost ~]# id tom
uid=1007(tom) gid=1011(tom) groups=1011(tom),1009(g3)
[root@localhost ~]# id mage
uid=1004(mage) gid=1004(mage) groups=1004(mage)
[root@localhost ~]# mkdir -p /data/testdir
[root@localhost ~]# chown :g1 /data/testdir
[root@localhost ~]# chmod g+wsx /data/testdir
[root@localhost ~]# ll -d /data/testdir
drwxrwsr-x. 2 root g1 6 Aug  3 16:43 /data/testdir
[root@localhost ~]# setfacl -m d:g:g2:rw /data/testdir
[root@localhost ~]# setfacl -m d:g:g3:r /data/testdir
[root@localhost ~]# setfacl -m g:g2:rwx /data/testdir
[root@localhost ~]# setfacl -m g:g3:r-x /data/testdir
[root@localhost ~]# setfacl -m o:--- /data/testdir
[root@localhost ~]# getfacl /data/testdir
getfacl: Removing leading '/' from absolute path names
# file: data/testdir
# owner: root
# group: g1
# flags: -s-
user::rwx
group::rwx
group:g2:rwx
group:g3:r-x
mask::rwx
other::---
default:user::rwx
default:group::rwx
default:group:g2:rw-
default:group:g3:r--
default:mask::rwx
default:other::r-x
[root@localhost ~]# su alice
[alice@localhost root]$ cd /data/testdir/
[alice@localhost testdir]$ echo aaa > aaa
[alice@localhost testdir]$ cat aaa
aaa
[alice@localhost testdir]$ ll
total 8
-rw-rw-r--+ 1 alice g1 4 Aug  3 16:46 aaa
[alice@localhost testdir]$ exit
exit
[root@localhost ~]# su tom 
[tom@localhost root]$ cd /data/testdir/
[tom@localhost testdir]$ ll
total 8
-rw-rw-r--+ 1 alice g1 4 Aug  3 16:46 aaa
[tom@localhost testdir]$ cat aaa
aaa
[tom@localhost testdir]$ echo aaaaa > aaa
bash: aaa: Permission denied
[tom@localhost testdir]$ echo aaaaa > tom
bash: tom: Permission denied
[tom@localhost testdir]$ ll
total 8
-rw-rw-r--+ 1 alice g1 4 Aug  3 16:46 aaa
[tom@localhost testdir]$ exit
exit
[root@localhost ~]# su mage
[mage@localhost root]$ cd /data/testdir/
bash: cd: /data/testdir/: Permission denied
[root@localhost ~]# setfacl -m d:o:--- /data/testdir/
[root@localhost ~]# getfacl /data/testdir/
getfacl: Removing leading '/' from absolute path names
# file: data/testdir/
# owner: root
# group: g1
# flags: -s-
user::rwx
group::rwx
group:g2:rwx
group:g3:r-x
mask::rwx
other::---
default:user::rwx
default:group::rwx
default:group:g2:rw-
default:group:g3:r--
default:mask::rwx
default:other::---

7、創建組sales,gid 3000,passwd:centos,sales admins:user2將用戶user1,user2,user3加入到sales輔助組,希望user1 創建新文件 默認的所屬組為sales,user2將用戶user3從sales組移除,刪除sales,user1,users。

[root@localhost ~]# groupadd -g 3000 sales
[root@localhost ~]# gpasswd sales
Changing the password for group sales
New Password:    ###centos
Re-enter new password:   ###centos
[root@localhost ~]# gpasswd -A user2 sales\
> ^C
[root@localhost ~]# gpasswd -A user2 sales
[root@localhost ~]# gpasswd -a user1 sales
Adding user user1 to group sales
[root@localhost ~]# gpasswd -a user2 sales
Adding user user2 to group sales
[root@localhost ~]# gpasswd -a user3 sales
Adding user user3 to group sales
[root@localhost ~]# groupmems -g sales -l
user1  user2  user3 
[root@localhost ~]# newgrp sales user1
[root@localhost ~]# su user1
[user1@localhost root]$ cd
[user1@localhost ~]$ touch user1
[user1@localhost ~]$ ll user1
-rw-rw-r--. 1 user1 user1 0 Aug  3 17:21 user1
[user1@localhost ~]$ newgrp sales user1
[user1@localhost ~]$ touch user2
[user1@localhost ~]$ ll user2
-rw-r--r--. 1 user1 sales 0 Aug  3 17:21 user2
[user1@localhost ~]$ exit
exit
[user1@localhost ~]$ exit
exit
[root@localhost ~]# su user2
[user2@localhost root]$ gpasswd -d user3 sales
Removing user user3 from group sales
[user2@localhost root]$ exit
exit
[root@localhost ~]# gpasswd -d user1
Usage: gpasswd [option] GROUP
Options:
  -a, --add USER                add USER to GROUP
  -d, --delete USER             remove USER from GROUP
  -h, --help                    display this help message and exit
  -Q, --root CHROOT_DIR         directory to chroot into
  -r, --delete-password         remove the GROUP's password
  -R, --restrict                restrict access to GROUP to its members
  -M, --members USER,...        set the list of members of GROUP
  -A, --administrators ADMIN,...
                                set the list of administrators for GROUP
Except for the -A and -M options, the options cannot be combined.
[root@localhost ~]# gpasswd -d user1 sales
Removing user user1 from group sales
[root@localhost ~]# gpasswd -d user2 sales
Removing user user2 from group sales
[root@localhost ~]# groupmems -g sales -l
[root@localhost ~]# groupdel sales

原創文章,作者:nieda_linux,如若轉載,請注明出處:http://www.www58058.com/29408

(0)
nieda_linuxnieda_linux
上一篇 2016-08-05 12:59
下一篇 2016-08-05 16:09

相關推薦

  • linux 學習(2)

    1 linux 常見的文件管理命令都有哪些?其常用的使用方法。 ls 文件列出命令   常見選項  -l 顯示長文本信息          -d 顯示當前目錄信息          -a 顯示所有文件信息     &nb…

    Linux干貨 2016-10-09
  • 自制一個小型Linux(附帶網絡功能)

      我們這次講述一下Linux啟動的啟動流程以及制作一個附帶網絡功能的mini linux 一、敘述 二、為什么要制作這么一個小型的系統 三、怎么制作 1、制作步驟 2、將虛擬機添加網絡功能 一、敘述   在制作一個小型的Linux之前,首先你得明白Linux系統的啟動過程,我們用一張圖來進行說明  二、為什…

    Linux干貨 2016-12-21
  • linux文件基本權限講解

    linux文件基本權限講解 Linux系統是一種典型的多用戶系統,不同的用戶處于不同的地位,擁有不同的權限。為了保護系統的安全性,Linux系統對不同的用戶訪問同一文件(包括目錄文件)的權限做了不同的規定。 Linux系統中一切都是文件,文件和目錄的所屬與權限——來分別規定所有者、所有組、其余人的讀,寫,執行權限。 在Linux中我們可以使用ll或者ls –…

    Linux干貨 2016-09-05
  • Redis學習手冊(持久化)

    一、Redis提供了哪些持久化機制:     1). RDB持久化:     該機制是指在指定的時間間隔內將內存中的數據集快照寫入磁盤。         2). AOF持久化:     該機制將以日志…

    Linux干貨 2015-02-25
  • 設計模式(十)享元模式Flyweight(結構型)

    相對于其它模式,Flyweight模式在PHP實現似乎沒有太大的意義,因為PHP的生命周期就在一個請求,請求執行完了,php占用的資源都被釋放。我們只是為了學習而簡單做了介紹。 1. 概述 面向對象技術可以很好地解決系統一些靈活性或可擴展性或抽象性的問題,但在很多情況下需要在系統中增加類和對象的個數。當對象數量太多時,將導致運行代價過高,帶來性能下降等問題?!?/p>

    Linux干貨 2015-07-08
  • 馬哥網絡教育班21期-第一周課程練習

      一、計算機的組成及其功能 1.1計算機的組成      1946年美籍匈牙利科學家馮·諾依曼提出存儲程序原理,把程序本身當作數據來對待,程序和該程序處理的數據用同樣的方式存儲,并確定了存儲程序計算機的五大組成部分,分別為運算器、控制器、存儲器、輸入設備和輸出設備。 1.2計算機的組成 控制器(Contro…

    Linux干貨 2016-07-12
欧美性久久久久