課堂練習
1、創建用戶gentoo,附加組為bin和root,默認shell為/bin/csh,注釋信息為“Gentoo Distribution”
useradd -G bin,root -s /bin/csh -c "Gentoo Distribution" gentoo
2、創建下面的用戶、組和組成員關系,名字為admins的組,用戶natasha,使用admins作為附屬組。用戶harry,也使用admins作為附屬組。用戶sarah,不可交互登錄系統,且不是admins的成員,natasha,harry,sarah密碼都是centos
注意:新建用戶,讓他不可交互登錄系統,useradd –s /sbin/nologin 用戶名 修改的時候,usermod –s /sbin/nologin 用戶名 修改密碼:passwd 用戶名
3、當用戶xiaoming對/testdir目錄無執行權限時,意味著無法做哪些操作?當用戶小強對/testdir目錄無讀權限時,意味著無法做哪些操作?對用戶wangcai對/testdir目錄無寫權限時,該目錄下的只讀文件file1是否可修改和刪除?復制/etc/fstab文件到/var/tmp下,設置文件所有者為wangcai讀寫權限,所屬組為sysadmins組有讀寫權限,其他人無權限。誤刪除了用戶wangcai的家目錄,請重建并恢復該用戶家目錄及相應的權限屬性
無執行權限時,無法進入目錄和無法查看目錄
無讀權限時,能進入目錄但無法查看里面的內容
無寫權限時,不能對目錄下的文件修改和刪除
有寫權限時,可以對目錄下的文件修改和刪除
課后作業
1、設置user1,使之新建文件權限為rw——-
[user1@localhost k]$ cd [user1@localhost ~]$ echo $(umask -p 066) >> .bashrc [user1@localhost ~]$ cat .bashre cat: .bashre: No such file or directory [user1@localhost ~]$ cat .bashrc # .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # Uncomment the following line if you don't like systemctl's auto-paging feature: # export SYSTEMD_PAGER= # User specific aliases and functions u=rwx,g=x,o=x [user1@localhost ~]$ [user1@localhost ~]$ [user1@localhost ~]$ [user1@localhost ~]$ . .bashrc [user1@localhost ~]$ touch l [user1@localhost ~]$ ll total 0 -rw------- 1 user1 user1 0 Aug 3 21:54 f1 -rw------- 1 user1 user1 0 Aug 3 21:54 f2 drwx--x--x 2 user1 user1 14 Aug 3 21:54 k -rw------- 1 user1 user1 0 Aug 3 21:57 l [user1@localhost ~]$ history
2、設置/testdir/f1的權限,使user1用戶不可以讀寫執行,g1組可以讀寫/testdir/dir的權限,使新建文件自動具有acl權限:user1:rw,g1:—備份/testdir目錄中所有文件的ACL,清除/testdir的所有ACL權限,并利用備份還原。
-rw-r--rw- 1 root root 0 Aug 3 22:04 dir drwxr-xr-x 4 root root 22 Jul 28 14:51 dir2x drwxr-xr-x 2 root root 6 Jul 28 14:51 dir2y -rw-r--r-- 1 root root 0 Aug 3 22:03 f1 -rw-r--r-- 1 root root 0 Aug 3 20:38 file1 [root@localhost testdir]# setfacl -m u:user1:0 f1 [root@localhost testdir]# getfacl f1 # file: f1 # owner: root # group: root user::rw- user:user1:--- group::r-- mask::r-- other::r-- [root@localhost testdir]# su - user1 Last login: Wed Aug 3 21:53:23 CST 2016 on pts/0 [user1@localhost ~]$ cd /testdir/ [user1@localhost testdir]$ ls dir dir2x dir2y f1 file1 [user1@localhost testdir]$ cat f1 cat: f1: Permission denied [user1@localhost testdir]$ cd /testdir/ 105 ll f1 106 chmod 644 f1 107 ll 108 setfacl -m u:user1:0 f1 109 getfacl f1 110 su - user1 111 chmod 640 /dir 112 chmod 640 dir 113 ll 114 chmod 644 dir 115 ll 116 setfacl -m g:g1:rw dir 117 getfacl dir 118 ls 119 rm dir 120 mkdir dir 121 setfacl -m g:g1:rw dir 122 detfacl -m d:u:user1:rw dir 123 setfacl -m d:u:user1:rw dir 124 setfacl -m d:g:g1:0 dir 125 touch3 126 touch 3 127 ll 128 getfacl dir 129 ll -d 130 ll -d /testdir/ 131 su - user1 132 chmod 777 dir 133 su - user1 134 getfacl -R /testdir/dir > /tmp/beifen 135 cat /tmp/beifen 136 cd .. 137 setfacl -b -R testdir/ 138 getfacl -R testdir/ 139 setfacl -R --set-file=beifen /testdir/dir 140 setfacl -R --set-file=beifen /testdir 141 setfacl -R --set-file=/tmp/beifen /testdir/ 142 getfacl dir 143 getfacl -R /testdir/ 144 cd 145 history
原創文章,作者:15152188070,如若轉載,請注明出處:http://www.www58058.com/28758