Linux作業練習---權限管理

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

[root@liang testdir]# su wangcai
[wangcai@liang testdir]$ ll -a
總用量 8
drwxr-xr-x.  2 4322 root 4096 8月   5 06:17 .
dr-xr-xr-x. 26 root root 4096 8月   5 03:28 ..
-r--r--r--.  1 root root    0 8月   5 06:17 file1
[wangcai@liang testdir]$ echo aaaaaaaaa >> file1 
bash: file1: 權限不夠
[wangcai@liang testdir]$ rm -f file1 
rm: 無法刪除"file1": 權限不夠

2、複製/etc/fstab文件到/var/tmp下,設置文件所有者爲wangcai,有讀寫權限,所屬組爲sysadmins組,有讀寫權限,其他人無權限

[root@liang tmp]# cp /etc/fstab /var/tmp/
[root@liang tmp]# ll
總用量 4
-rw-r--r--. 1 root root 805 8月   5 06:25 fstab
[root@liang tmp]# chown wangcai:sysadmins fstab 
[root@liang tmp]# chmod 660 fstab 
[root@liang tmp]# ll
總用量 4
-rw-rw----. 1 wangcai sysadmins 805 8月   5 06:25 fstab

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

[root@liang home]# mkdir wangcai
[root@liang home]# cp -r /etc/skel/. /home/wangcai/
[root@liang home]# chown -R wangcai:wangcai wangcai/
[root@liang home]# ll -a wangcai/
總用量 24
drwxr-xr-x.  3 wangcai wangcai 4096 8月   5 06:29 .
drwxr-xr-x. 18 root    root    4096 8月   5 06:29 ..
-rw-r--r--.  1 wangcai wangcai   18 8月   5 06:29 .bash_logout
-rw-r--r--.  1 wangcai wangcai  176 8月   5 06:29 .bash_profile
-rw-r--r--.  1 wangcai wangcai  124 8月   5 06:29 .bashrc
drwxr-xr-x.  2 wangcai wangcai 4096 8月   5 06:29 .gnome2

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

[root@liang /]# groupadd g1
[root@liang /]# groupadd g2
[root@liang /]# groupadd g3
[root@liang /]# useradd -G g2 alice
[root@liang /]# useradd -G g3 tom
[root@liang /]# id alice
uid=4327(alice) gid=4331(alice) 組=4331(alice),4329(g2)
[root@liang /]# id tom
uid=4328(tom) gid=4332(tom) 組=4332(tom),4330(g3)
[root@liang /]# mkdir -p /data/testdir
[root@liang /]# cd /data/
[root@liang data]# ll
總用量 4
drwxr-xr-x. 2 root root 4096 8月   5 06:39 testdir
[root@liang data]# chgrp g1 testdir/
[root@liang data]# chmod g+sw,o= testdir/
[root@liang data]# ll
總用量 4
drwxrws---. 2 root g1 4096 8月   5 06:48 testdir
[root@liang data]# setfacl -m g:g2:rwx,g:g3:rwx testdir/
[root@liang data]# setfacl -m d:g:g2:rw,d:g:g3:r testdir/
[root@liang data]# getfacl testdir/
# file: testdir/
# owner: root
# group: g1
# flags: -s-
user::rwx
group::rwx
group:g2:rwx
group:g3:rwx
mask::rwx
other::---
default:user::rwx
default:group::rwx
default:group:g2:rw-
default:group:g3:r--
default:mask::rwx
default:other::---

5、設置user1,使之新建文件權限爲rw-------

[root@liang /]# su - user1
[user1@liang ~]$ umask u=rw,g=,o=
[user1@liang ~]$ umask -p >> .bashrc 
[user1@liang ~]$ cat .bashrc 
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

# User specific aliases and functions
umask 0177

6、設置/testdir/f1的權限,使user1用戶不可以讀寫執行,g1組可以讀寫,

設置/testdir/dir的權限,使新建文件自動具有acl權限:user1:rw,g1:---,

備份/testdir目錄中所有文件的ACL,清除/testdir的所有ACL權限,並利用備份還原

[root@liang /]# ll testdir/
總用量 4
drwxr-xr-x. 2 root root 4096 8月   5 07:27 dir
-rw-r--r--. 1 root root    0 8月   5 07:27 f1
[root@liang /]# setfacl -m u:user1:0,g:g1:rw /testdir/f1
[root@liang /]# setfacl -m d:u:user1:rw,d:g:g1:0 /testdir/dir/
[root@liang /]# getfacl -R /testdir/ > acl.txt
[root@liang /]# setfacl -R -b /testdir/
[root@liang /]# setfacl -R --set-file=acl.txt /testdir/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章