2.linux文件管理与权限管理
2022-03-13
1、显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
2、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
3、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
4、请总结描述用户和组管理类命令的使用方法并完成以下练习:
(1)、创建组distro,其GID为2019;
(2)、创建用户mandriva, 其ID号为1005;基本组为distro;
(3)、创建用户mageia,其ID号为1100,家目录为/home/linux;
(4)、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
(5)、删除mandriva,但保留其家目录;
(6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
(7)、修改slackware的默认shell为/bin/tcsh;
(8)、为用户slackware新增附加组admins,并设置不可登陆。
5、创建用户user1、user2、user3。在/data/下创建目录test
(1)、目录/data/test属主、属组为user1
(2)、在目录属主、属组不变的情况下,user2对文件有读写权限
(3)、user1在/data/test目录下创建文件a1.sh, a2.sh, a3.sh, a4.sh,设置所有用户都不可删除1.sh,2.sh文件、除了user1及root之外,所有用户都不可删除a3.sh, a4.sh
(4)、user3增加附加组user1,同时要求user1不能访问/data/test目录及其下所有文件
(5)、清理/data/test目录及其下所有文件的acl权限
1.显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
[:digit:]:任意数字,相当于0-9 [:lower:]:任意小写字母,表示 a-z [:upper:]: 任意大写字母,表示 A-Z [:alpha:]: 任意大小写字母 [:alnum:]:任意数字或字母 [:blank:]:水平空白字符 [:space:]:水平或垂直空白字符 [:punct:]:标点符号 [:print:]:可打印字符 [:cntrl:]:控制(非打印)字符 [:graph:]:图形字符 [:xdigit:]:十六进制字符 [root@centos7-v1 ~]#cd /etc/ [root@centos7-v1 etc]#mkdir 1aa [root@centos7-v1 etc]#touch 1aa.txt [root@centos7-v1 etc]#ls /etc/ | grep ^[^[:alpha:]][[:alpha:]].* 1aa 1aa.txt
2.复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中。
[root@centos7-v1 etc]#mkdir /tmp/mytest1 mkdir: cannot create directory ‘/tmp/mytest1’: File exists [root@centos7-v1 etc]#cp -r /etc/p*[^[:digit:]] /tmp/mytest1 [root@centos7-v1 etc]#ll /tmp/mytest1/ total 68 drwxr-xr-x 2 root root 4096 Mar 13 06:09 pam.d -rw-r--r-- 1 root root 68 Mar 13 06:09 papersize -rw-r--r-- 1 root root 2576 Mar 13 06:09 passwd -rw-r--r-- 1 root root 2535 Mar 13 06:09 passwd- -rw-r--r-- 1 root root 1362 Mar 13 06:09 pbm2ppa.conf drwxr-xr-x 9 root root 104 Mar 13 06:09 pcp -rw-r--r-- 1 root root 6460 Mar 13 06:09 pcp.conf -rw-r--r-- 1 root root 6662 Mar 13 06:09 pcp.env -rw-r--r-- 1 root root 2872 Mar 13 06:09 pinforc drwxr-xr-x 13 root root 165 Mar 13 06:09 pki drwxr-xr-x 2 root root 28 Mar 13 06:09 plymouth drwxr-xr-x 5 root root 52 Mar 13 06:09 pm -rw-r--r-- 1 root root 6300 Mar 13 06:09 pnm2ppa.conf drwxr-xr-x 2 root root 6 Mar 13 06:09 popt.d drwxr-xr-x 2 root root 154 Mar 13 06:09 postfix drwxr-xr-x 3 root root 219 Mar 13 06:09 ppp drwxr-xr-x 2 root root 105 Mar 13 06:09 prelink.conf.d -rw-r--r-- 1 root root 233 Mar 13 06:09 printcap -rw-r--r-- 1 root root 1819 Mar 13 06:09 profile drwxr-xr-x 2 root root 4096 Mar 13 06:09 profile.d -rw-r--r-- 1 root root 6545 Mar 13 06:09 protocols drwxr-xr-x 2 root root 79 Mar 13 06:09 pulse drwxr-xr-x 2 root root 23 Mar 13 06:09 purple drwxr-xr-x 2 root root 35 Mar 13 06:09 python
3.将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中
[root@centos7-v1 ~]#cat /etc/issue | tr 'a-z' 'A-Z' > /tmp/issue.out [root@centos7-v1 ~]#cat /etc/issue \S Kernel \r on an \m [root@centos7-v1 ~]#cat /tmp/issue.out \S KERNEL \R ON AN \M [root@centos7-v1 ~]#
4.请总结描述用户和组管理类命令的使用方法并完成以下练习
(1)、创建组distro,其GID为2019;
[root@centos7-v1 ~]#groupadd -g 2019 distro
(2)、创建用户mandriva, 其ID号为1005;基本组为distro;
[root@centos7-v1 ~]#useradd -u 1005 -g distro mandriva [root@centos7-v1 ~]#id mandriva uid=1005(mandriva) gid=2019(distro) groups=2019(distro)
(3)、创建用户mageia,其ID号为1100,家目录为/home/linux;
[root@centos7-v1 ~]#useradd -d /home/linux -u 1100 mageia [root@centos7-v1 ~]#id mageia uid=1100(mageia) gid=1100(mageia) groups=1100(mageia)
(4)、给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期
[root@centos7-v1 ~]#echo mageedu | passwd --stdin mageia Changing password for user mageia. passwd: all authentication tokens updated successfully. [root@centos7-v1 ~]#passwd -x 7 mageia Adjusting aging data for user mageia. passwd: Success
(5)、删除mandriva,但保留其家目录;
[root@centos7-v1 ~]#userdel mandriva [root@centos7-v1 ~]#ll /home/linux/ total 0 [root@centos7-v1 ~]#ll /home/ total 0 drwx------ 3 mageia mageia 78 Mar 13 06:21 linux drwx------. 3 mage mage 91 Jan 23 22:10 mage drwx------ 3 1005 distro 78 Mar 13 06:20 mandriva drwx------. 3 test test 78 Jan 22 00:13 test drwx------. 3 xiaoming xiaoming 78 Jan 26 01:27 xiaoming
(6)、创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;
[root@centos7-v1 ~]#groupadd peguin [root@centos7-v1 ~]#useradd -u 2002 -g distro -G peguin slackware [root@centos7-v1 ~]#id slackware uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
(7)、修改slackware的默认shell为/bin/tcsh;
[root@centos7-v1 ~]#usermod -s /bin/tcsh slackware [root@centos7-v1 ~]#cat /etc/passwd | grep slackware slackware:x:2002:2019::/home/slackware:/bin/tcsh
(8)、为用户slackware新增附加组admins,并设置不可登陆。
[root@centos7-v1 ~]#groupadd admins [root@centos7-v1 ~]#usermod -aG admins slackware [root@centos7-v1 ~]#id slackware uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins) [root@centos7-v1 ~]#cat /etc/passwd | grep slackware slackware:x:2002:2019::/home/slackware:/bin/tcsh
5.创建用户user1、user2、user3。在/data/下创建目录test
[root@centos7-v1 ~]#useradd user1 [root@centos7-v1 ~]#useradd user2 [root@centos7-v1 ~]#useradd user3 [root@centos7-v1 ~]#mkdir -p /data/test [root@centos7-v1 ~]#cat /etc/passwd | grep user* saned:x:995:992:SANE scanner daemon user:/usr/share/sane:/sbin/nologin saslauth:x:994:76:Saslauthd user:/run/saslauthd:/sbin/nologin radvd:x:75:75:radvd user:/:/sbin/nologin qemu:x:107:107:qemu user:/:/sbin/nologin tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin oprofile:x:16:16:Special user account to be used by OProfile:/var/lib/oprofile:/sbin/nologin user1:x:2003:2003::/home/user1:/bin/bash user2:x:2004:2004::/home/user2:/bin/bash user3:x:2005:2005::/home/user3:/bin/bash
(1)、目录/data/test属主、属组为user1
[root@centos7-v1 ~]#ll /data/ total 0 drwxr-xr-x 2 root root 52 Feb 8 03:32 httpd drwxr-xr-x. 5 root root 41 Jan 24 08:47 mysql crw-r--r-- 1 root root 1, 3 Feb 9 06:49 null brw-rw---- 1 root disk 8, 1 Feb 8 03:27 sda1 drwxr-xr-x 2 root root 6 Mar 13 06:32 test prw-r--r-- 1 root root 0 Mar 3 09:37 test.fifo drwxr-xr-x. 2 root root 6 Jan 26 00:23 www [root@centos7-v1 ~]#chown -R user1.user1 /data/test [root@centos7-v1 ~]#ll /data/ total 0 drwxr-xr-x 2 root root 52 Feb 8 03:32 httpd drwxr-xr-x. 5 root root 41 Jan 24 08:47 mysql crw-r--r-- 1 root root 1, 3 Feb 9 06:49 null brw-rw---- 1 root disk 8, 1 Feb 8 03:27 sda1 drwxr-xr-x 2 user1 user1 6 Mar 13 06:32 test prw-r--r-- 1 root root 0 Mar 3 09:37 test.fifo drwxr-xr-x. 2 root root 6 Jan 26 00:23 www [root@centos7-v1 ~]#
(2)、在目录属主、属组不变的情况下,user2对文件有读写权限
[root@centos7-v1 ~]#setfacl -R -m u:user2:rw /data/test [root@centos7-v1 ~]#getfacl /data/test getfacl: Removing leading '/' from absolute path names # file: data/test # owner: user1 # group: user1 user::rwx user:user2:rw- group::r-x mask::rwx other::r-x
(3)、user1在/data/test目录下创建文件a1.sh, a2.sh, a3.sh, a4.sh,设置所有用户都不可删除1.sh,2.sh文件、除了user1及root之外,所有用户都不可删除a3.sh, a4.sh
[root@centos7-v1 ~]#cd /data/test/ [root@centos7-v1 test]#ll total 0 [root@centos7-v1 test]#touch a{1..4}.sh [root@centos7-v1 test]#ll total 0 -rw-r--r-- 1 root root 0 Mar 13 06:40 a1.sh -rw-r--r-- 1 root root 0 Mar 13 06:40 a2.sh -rw-r--r-- 1 root root 0 Mar 13 06:40 a3.sh -rw-r--r-- 1 root root 0 Mar 13 06:40 a4.sh [root@centos7-v1 test]#chattr +i a1.sh a2.sh [root@centos7-v1 test]#lsattr ----i----------- ./a1.sh ----i----------- ./a2.sh ---------------- ./a3.sh ---------------- ./a4.sh [root@centos7-v1 test]#chmod o+t a3.sh a4.sh [root@centos7-v1 test]#ll total 0 -rw-r--r-- 1 root root 0 Mar 13 06:40 a1.sh -rw-r--r-- 1 root root 0 Mar 13 06:40 a2.sh -rw-r--r-T 1 root root 0 Mar 13 06:40 a3.sh -rw-r--r-T 1 root root 0 Mar 13 06:40 a4.sh [root@centos7-v1 test]#ll ../ total 0 drwxr-xr-x 2 root root 52 Feb 8 03:32 httpd drwxr-xr-x. 5 root root 41 Jan 24 08:47 mysql crw-r--r-- 1 root root 1, 3 Feb 9 06:49 null brw-rw---- 1 root disk 8, 1 Feb 8 03:27 sda1 drwxrwxr-x+ 2 user1 user1 58 Mar 13 06:40 test prw-r--r-- 1 root root 0 Mar 3 09:37 test.fifo drwxr-xr-x. 2 root root 6 Jan 26 00:23 www [root@centos7-v1 test]#
(4)、user3增加附加组user1,同时要求user1不能访问/data/test目录及其下所有文件
[root@centos7-v1 test]#id user3 uid=2005(user3) gid=2005(user3) groups=2005(user3) [root@centos7-v1 test]#usermod -G user1 user3 [root@centos7-v1 test]#id user3 uid=2005(user3) gid=2005(user3) groups=2005(user3),2003(user1) [root@centos7-v1 test]#ll -d /data/test drwxrwxr-x+ 2 user1 user1 58 Mar 13 06:40 /data/test [root@centos7-v1 test]#chmod -x /data/test [root@centos7-v1 test]#ll -d /data/test drw-rw-r--+ 2 user1 user1 58 Mar 13 06:40 /data/test
(5)、清理/data/test目录及其下所有文件的acl权限
[root@centos7-v1 test]#getfacl /data/test getfacl: Removing leading '/' from absolute path names # file: data/test # owner: user1 # group: user1 user::rw- user:user2:rw- group::r-x #effective:r-- mask::rw- other::r-- [root@centos7-v1 test]#setfacl -R -b /data/test [root@centos7-v1 test]#getfacl /data/test getfacl: Removing leading '/' from absolute path names # file: data/test # owner: user1 # group: user1 user::rw- group::r-- other::r-- [root@centos7-v1 test]#
posted on 2022-03-13 18:46 N64_849411472 阅读(81) 评论(0) 编辑 收藏 举报