运维笔记13 (用户的权限列表,系统延时与定期任务,系统临时文件的管理)

来源:互联网 发布:中级c 程序员面试问题 编辑:程序博客网 时间:2024/05/29 16:30

概述:

用户权限列表,一般的权限规定的范围过大,我们有时需要更细致的权限设定,比如某个目录只对某用户有约束,这时就需要acl权限。我们肯定用过闹钟,闹钟就是一个定时任务,在每天的某个时间运行,linux也有这样的机制,比如at与crontab命令。有些目录下的文件是临时文件,定期需要进行清理,我们可以使用systemd-tmpfiles来完成。

1.用户权限列表


指定特殊用户对某个文件有特殊权限的记录表格。

一般文件:

-rw-r--r--. 1 root root 0 11月  1 20:05 test
指定acl后的文件:

-rw-rwxr--+ 1 root root 0 11月  1 20:05 test

分析上面的差别可以发现,以正常的ls -l命令查看的文件权限和一开始的不一样,但是我们只是修改了acl权限呀,对本来的权限没有修改,这里强调一下,当你设定用户的acl权限后,文件权限的文件就被改写了,ls -l所显示的是不对的,只有通过权限列表查看命令查看才能获得正确的文件权限。

1.1).权限列表的查看

getfacl

一般文件:

[root@2+2 ~]# getfacl test1# file: test1# owner: root# group: rootuser::rw-group::r--other::r--
指定acl后的文件

[root@2+2 ~]# getfacl test# file: test<span style="white-space:pre"></span>#文件名称# owner: root<span style="white-space:pre"></span>#文件所有人
# group: root<span style="white-space:pre"></span>#文件所有组user::rw-<span style="white-space:pre"></span>#所有人权限user:mo:rwx<span style="white-space:pre"></span>#特殊指定用户的权限group::r--<span style="white-space:pre"></span>#组权限mask::rwx<span style="white-space:pre"></span>#权限阈值other::r--<span style="white-space:pre"></span>#其他人权限
1.2).设定acl列表

setfacl -m u:username:权限(rwx) file  #指定username用户对file文件可读可写

setfacl -m g:groupname:权限(rwx)file #设定group组对该文件的权限

setfacl -x u:usernamefile #删除列表中的student信息

setfacl -b  file #关闭列表


1.3).mask权限阈值

当一个文件有acl权限时尽量不要对这个文件使用chmod命令,因为他的修改会莫名其妙的改变acl列表,比如chmod的时候会修改mask的值。

[root@2+2 ~]# chmod 700 test[root@2+2 ~]# getfacl test# file: test# owner: root# group: rootuser::rwxgroup::r--#effective:---group:mo:rwx#effective:---<span style="color:#ff0000;">mask::---</span>other::---[root@2+2 ~]# chmod 777 test[root@2+2 ~]# getfacl test# file: test# owner: root# group: rootuser::rwxgroup::r--group:mo:rwx<span style="color:#ff0000;">mask::rwx</span>other::rwx
我们并没有使用setfacl选项可是mask就被修改了。

mask为特殊用户能够获得到的最大权限值

如过设定mask为rw-那么这个文件最多有读写权限,不可以有执行权限。

设定方式:

setfacl -m m:权限  filename

[root@2+2 ~]# getfacl test1# file: test1# owner: root# group: rootuser::rwxuser:mo:rwx#effective:rw-group::r--mask::rw-other::rwx

1.3).默认权限

[root@2+2 ~]# setfacl -m u:mo:r-- test[root@2+2 ~]# getfacl test/# file: test/# owner: root# group: rootuser::rwxuser:mo:r--group::r-xmask::r-xother::r-x[root@2+2 ~]# cd test/[root@2+2 test]# ls[root@2+2 test]# mkdir test1[root@2+2 test]# getfacl test1# file: test1# owner: root# group: rootuser::rwxgroup::r-xother::r-x

我们对test目录设定mo用户只有读权限,在test下又创建了test1目录,但是getfacl后发现test1目录没有继承test的那一属性,这不是我们想要的,如果想要继承这个属性,我们可以设置默认默认权限。

[root@2+2 test]# setfacl -m d:u:mo:r-- test1/

tips:默认权限对已有文件不生效,默认权限对目录本身不生效。


2系统延迟及定时机制

2.1).at延时

at time进入at设定界面

[root@foundation3 ~]# at now+1minat> touch at_testat> <EOT>job 2 at Tue Nov  1 20:47:00 2016
at -l #显示当前的at任务

atrm 任务号 #删除这个at任务

tips:比如你输入at now+1min,当前时间是10:59:59,那么当你输入完成后,这个任务基本上是马上执行的,因为at的加1min意思是在11:00:00执行,不管你在59分已经过了多少秒。当你的任务有内容输出的时候,这个内容会议邮件的形式发给你。

在/etc下游at的黑白名单

/etc/at.deny #黑名单,默认存在

/etc/at.allow #白名单,默认不存在,一旦存在黑名单失效

2.2)定期任务,crontab命令

输入crontab -u root -e后会进入一个文本编辑界面你在里面输入:

MM   hh   dd   mm   ww

 分 小时 天   月      周

MM/2 #表示每隔两分钟

hh1-hh2 #表示多少点到多少点

hh1,hh2 #表示多少点和多少点

crontab -u username -r #删除这个用户所有的任务


以文件的方式发起定时命令

vim /etc/cron.d/filename

[root@foundation3 ~]# ls /etc/cron.d0hourly  raid-check  sysstat  unbound-anchor
在这个目录下创建一个文件写入如下格式即可发起:

MM hh dd mm ww USERNAME 动作


对哪些用户可以发起crontanb命令的限制也在/etc下

/etc/cron.deny #黑名单

/etc/cron.allow #白名单


3.系统临时文件的管理

在/usr/lib/tmpfiles.d下建立一个以.conf结尾的文件

文件的内容为指定临时文件的目录

type  filename  perm  user  group  time

d  /mnt/test  1777  root   root     10s

文件类型为目录,权限为所有人可以读写执行,但是只能删除自己创建的文件,文件存在10s后才可删除。

systemd-tmpfiles --create /usr/lib/tmpfiles.d/*.conf#建立临时文件目录

systemd-tmpfiles --clean /usr/lib/tmpfiles.d/*.conf#清空临时文件










3 0