Linux权限管理练习
1、当用户xiaoming对/testdir 目录无执行权限时,意味着无法做哪些操作?无法cd切换进入此目录,无法创建文件,无法删除文件,无法查看里面文件的内容,只能ls列出目录下的内容
2、当用户xiaoqiang对/testdir 目录无读权限时,意味着无法做哪些操作?
无法ls查看目录下的内容
3、当用户wangcai 对/testdir 目录无写权限时,该目录下的只读文件file1是否可修改和删除?
无法修改也无法删除
4、复制/etc/fstab文件到/var/tmp下,设置文件所有者为wangcai读写权限,所属组为sysadmins组有读写权限,其他人无权限。
# cp /etc/fstab /var/tmp/
# chmod 660 /var/tmp/fstab
# chown wangcai.sysadmins /var/tmp/fstab
# ll /var/tmp/fstab
-rw-rw----. 1 wangcai sysadmins 595 Aug3 15:29 /var/tmp/fstab 5、误删除了用户wangcai的家目录,请重建并恢复该用户家目录及相应的权限属性
# cp -r /etc/skel/ /home/wangcai
# chown -R wangcai.wangcai /home/wangcai
# chmod 700 /home/wangcai
# chmod 644 /home/wangcai/.bash
.bash_logout .bash_profile.bashrc
# chmod 644 /home/wangcai/.bash*# ll /home/wangcai/ -a
total 12
drwx------. 3 wangcai wangcai74 Aug3 15:31 .
drwxr-xr-x. 6 root root 52 Aug3 15:31 ..
-rw-r--r--. 1 wangcai wangcai18 Aug3 15:31 .bash_logout
-rw-r--r--. 1 wangcai wangcai 193 Aug3 15:31 .bash_profile
-rw-r--r--. 1 wangcai wangcai 231 Aug3 15:31 .bashrc
drwxr-xr-x. 4 wangcai wangcai37 Aug3 15:31 .mozilla 6、在/data/testdir里创建的新文件自动属于g1组,组g2的成员如:alice能对这些新文件有读写权限,组g3的成员如:tom只能对新文件有读权限,其它用户(不属于g1,g2,g3)不能访问这个文件夹。
# id alice
uid=1006(alice) gid=1010(alice) groups=1010(alice),1008(g2)
# id tom
uid=1007(tom) gid=1011(tom) groups=1011(tom),1009(g3)
# id mage
uid=1004(mage) gid=1004(mage) groups=1004(mage)
# mkdir -p /data/testdir
# chown :g1 /data/testdir
# chmod g+wsx /data/testdir
# ll -d /data/testdir
drwxrwsr-x. 2 root g1 6 Aug3 16:43 /data/testdir
# setfacl -m d:g:g2:rw /data/testdir
# setfacl -m d:g:g3:r /data/testdir
# setfacl -m g:g2:rwx /data/testdir
# setfacl -m g:g3:r-x /data/testdir
# setfacl -m o:--- /data/testdir
# 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
# su alice
$ cd /data/testdir/
$ echo aaa > aaa
$ cat aaa
aaa
$ ll
total 8
-rw-rw-r--+ 1 alice g1 4 Aug3 16:46 aaa
$ exit
exit
# su tom
$ cd /data/testdir/
$ ll
total 8
-rw-rw-r--+ 1 alice g1 4 Aug3 16:46 aaa
$ cat aaa
aaa
$ echo aaaaa > aaa
bash: aaa: Permission denied
$ echo aaaaa > tom
bash: tom: Permission denied
$ ll
total 8
-rw-rw-r--+ 1 alice g1 4 Aug3 16:46 aaa
$ exit
exit
# su mage
$ cd /data/testdir/
bash: cd: /data/testdir/: Permission denied# setfacl -m d:o:--- /data/testdir/
# 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。
# groupadd -g 3000 sales
# gpasswd sales
Changing the password for group sales
New Password: ###centos
Re-enter new password: ###centos
# gpasswd -A user2 sales\
> ^C
# gpasswd -A user2 sales
# gpasswd -a user1 sales
Adding user user1 to group sales
# gpasswd -a user2 sales
Adding user user2 to group sales
# gpasswd -a user3 sales
Adding user user3 to group sales
# groupmems -g sales -l
user1user2user3
# newgrp sales user1
# su user1
$ cd
$ touch user1
$ ll user1
-rw-rw-r--. 1 user1 user1 0 Aug3 17:21 user1
$ newgrp sales user1
$ touch user2
$ ll user2
-rw-r--r--. 1 user1 sales 0 Aug3 17:21 user2
$ exit
exit
$ exit
exit
# su user2
$ gpasswd -d user3 sales
Removing user user3 from group sales
$ exit
exit
# gpasswd -d user1
Usage: gpasswd 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.
# gpasswd -d user1 sales
Removing user user1 from group sales
# gpasswd -d user2 sales
Removing user user2 from group sales
# groupmems -g sales -l
# groupdel sales
页:
[1]