文件管理 特殊权限

来源:互联网 发布:数据资产管理 编辑:程序博客网 时间:2024/05/18 17:42
#################################

1.文件属性查看

eg:

[root@foundation38 mnt]# touch file

[root@foundation38 mnt]# ls -l file


   -                  rw-r--r--             1                       root              root            0           Oct 31 19:36              file


文件类型    文件权限   文件副本个数        文件所有人  文件所有组    大小    最后一次被修改的时间    名字
####################################

2.查看目录属性

eg:

[root@foundation38 mnt]# mkdir westos
[root@foundation38 mnt]# touch westos/file{1..5}

[root@foundation38 mnt]# ls -ld westos


 d     rwxr-xr-x            2               root             root               66                    Oct 31 19:39          westos


类型    权限       子目录个数 目录所有人  目录所有组 子文件属性大小    目录中内容变化        目录名字


##################################################


3.文件用户组的更改

chown    用户名称    文件    ##更改文件所有人
chgrp    组名称        文件    ##更改文件所有组

chown -R 用户        目录    ##更改目录本身以及目录中的子文件的所有人

chgrp -R 组名        目录    ##更改目录本身以及目录中的子文件的所有组

eg:

[root@foundation38 mnt]# chown kiosk file
[root@foundation38 mnt]# ls -ld file
-rw-r--r-- 1 kiosk root 0 Oct 31 19:36 file
[root@foundation38 mnt]# chgrp kiosk file
[root@foundation38 mnt]# ls -ld file
-rw-r--r-- 1 kiosk kiosk 0 Oct 31 19:36 file
[root@foundation38 mnt]# chgrp -R kiosk westos
[root@foundation38 mnt]# ls -ld westos
drwxr-xr-x 2 root kiosk 66 Oct 31 19:39 westos
[root@foundation38 mnt]# ls -ld westos/file*
-rw-r--r-- 1 root kiosk 0 Oct 31 19:39 westos/file1
-rw-r--r-- 1 root kiosk 0 Oct 31 19:39 westos/file2
-rw-r--r-- 1 root kiosk 0 Oct 31 19:39 westos/file3
-rw-r--r-- 1 root kiosk 0 Oct 31 19:39 westos/file4
-rw-r--r-- 1 root kiosk 0 Oct 31 19:39 westos/file5
[root@foundation38 mnt]# chown -R kiosk westos
[root@foundation38 mnt]# chown -R kiosk westos/file*
[root@foundation38 mnt]# ls -ld westos/file*
-rw-r--r-- 1 kiosk kiosk 0 Oct 31 19:39 westos/file1
-rw-r--r-- 1 kiosk kiosk 0 Oct 31 19:39 westos/file2
-rw-r--r-- 1 kiosk kiosk 0 Oct 31 19:39 westos/file3
-rw-r--r-- 1 kiosk kiosk 0 Oct 31 19:39 westos/file4
-rw-r--r-- 1 kiosk kiosk 0 Oct 31 19:39 westos/file5
[root@foundation38 mnt]# ls -ld westos
drwxr-xr-x 2 kiosk kiosk 66 Oct 31 19:39 westos

#######################################

4.权限的识别
ls -l 中2-10字符为文件权限
rwx        r-x        r-x
用户权限     组成员权限      其他用户权限

权限种类
r
r权限针对文件,表示可以查看文件内容
r权限针对目录,表示可以ls 查看目录中存在的文件名称

w
w权限针对文件,表示可以更改文件的内容
w权限针对目录,表示是否可以删除目录中的子文件或者子目录

x
x权限对于文件,表示是否可以开启文件当中记录的程序
x权限对于目录,表示是否可以进入目录中

chmod    ugo+-=rwx           ##改权限


7=rwx,6=rw-,5=r-x,4=r--,3=-wx,2=-w-,1=--x,0=---

##################################
5.文件的默认权限

 umask                               ##显示系统预留权限

eg:

[root@foundation38 mnt]# umask
0022
vim /etc/bashrc        71行是普通用户的更改,73是超级用户的更改

 67     # Current threshold for system reserved uid/gids is 200
 68     # You could check uidgid reservation validity in
 69     # /usr/share/doc/setup-*/uidgid file
 70     if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
 71        umask 002
 72     else
 73        umask 022
 74     fi
 75

vim /etc/profile    60行是普通用户的更改,62是超级用户的更改

eg:

 56 # Current threshold for system reserved uid/gids is 200
 57 # You could check uidgid reservation validity in
 58 # /usr/share/doc/setup-*/uidgid file
 59 if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
 60     umask 002
 61 else
 62     umask 022
 63 fi

source /etc/bashrc     ##刷新bash配置
source /etc/profile     ##刷新系统配置
###################################
6.特殊权限

stickyid                     ###强制位
o+t                           ###针对目录,当一个目录上有t权限时,

                               ###这个目录中的文件只能被文件拥有者删除
t=1
chmod o+t directroy
chmod 1777 directory

eg:

[hello@foundation38 ~]$ touch file
[hello@foundation38 ~]$ pwd
/home/hello
[hello@foundation38 ~]$ chmod o+t file
[hello@foundation38 ~]$ ls -ld file
-rw-rw-r-T 1 hello hello 0 Oct 31 20:27 file
[hello@foundation38 ~]$ su - kiosk
Password:
Last login: Mon Oct 31 19:31:09 CST 2016 on :0
Last failed login: Mon Oct 31 20:27:33 CST 2016 on pts/0
There was 1 failed login attempt since the last successful login.
[kiosk@foundation38 ~]$ rm -fr /home/hello/file
rm: cannot remove ‘/home/hello/file’: Permission denied

sgid                        ###粘制位
g+s                        ##针对目录,在目录中创建的文件都自动归属到目录所在组,

                             ###针对二进制文件,文件内记录的程序在执行时和执行者的组身份没有关系,

                            ###而是以二进制文件的所有组的身份执行的
chmod g+s file|directory
chmod 2777 file|directory
eg:
[kiosk@foundation38 Desktop]$ chmod g+s westos
[kiosk@foundation38 Desktop]$ cd westos
[kiosk@foundation38 westos]$ ls -ld file*
-rw-rw-r-- 1 kiosk kiosk 0 Oct 31 20:43 file
-rw-r--r-- 1 root  root  0 Oct 31 20:43 file1
[kiosk@foundation38 westos]$ su root
Password:
su: Authentication failure
[kiosk@foundation38 westos]$ su root
Password:
[root@foundation38 westos]# touch file2
[root@foundation38 westos]# ls -ld file*
-rw-rw-r-- 1 kiosk kiosk 0 Oct 31 20:43 file
-rw-r--r-- 1 root  root  0 Oct 31 20:43 file1
-rw-r--r-- 1 root  kiosk 0 Oct 31 20:45 file2

suid                        ###冒险位
u+s                        ###针对文件,文件记录动作在执行时是一文件所有人身份执行的,

                             ###与是谁发起的无关
chmod u+s file
chmod 4777 fileg+s


kiosk@foundation38 Desktop]$ touch file
[kiosk@foundation38 Desktop]$ chmod u+s file
[kiosk@foundation38 Desktop]$ ls -ld file
-rwSrw-r-- 1 kiosk kiosk 0 Oct 31 20:51 file

################################################

7.用户权限
指定特殊权限用户对某个文件有特殊权限的记录表
getfacl filename ##读取文件权限列表

eg:

[hello@foundation38 mnt]$ getfacl file
# file: file                            ##文件名称
# owner: root                     ##文件所有人
# group: root                      ##文件所有组
user::rw-                            ##用户权限
group::r--                           ##组权限
other::r--                            ##其他人权限

setfacl -m u:username:权限       ##授予用户特殊权限
setfacl -x u:用户 filename          ##删除用户的特殊权限
setfacl -b  filename                    ##关闭列表

setfacl -m g:groupname:权限    ##授予组特殊权限

setfacl -m o::- filename              ##修改其他所有人的权限为空

eg:

[root@foundation38 mnt]# setfacl -m u:kiosk:rwx file
[root@foundation38 mnt]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
user:kiosk:rwx
group::r--
mask::rwx
other::r--
[root@foundation38 mnt]# setfacl -x u:kiosk file
[root@foundation38 mnt]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
group::r--
mask::r--
other::r--

[root@foundation38 mnt]# setfacl -m u:kiosk:rwx file
[root@foundation38 mnt]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
user:kiosk:rwx
group::r--
mask::rwx
other::r--

[root@foundation38 mnt]# setfacl -b file
[root@foundation38 mnt]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
group::r--
other::r--
[root@foundation38 mnt]# setfacl -m g:kiosk:rwx file
[root@foundation38 mnt]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
group::r--
group:kiosk:rwx
mask::rwx
other::r--

[root@foundation38 mnt]# setfacl -m o::- file
[root@foundation38 mnt]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
group::r--
group:kiosk:rwx
mask::rwx
other::---

mask 权限阀值

具有ACL的文件拥有一个“mask(掩码)”,

这个掩码既能够限制拥有该文件的最大权限,

又能够限制ACL中的补充用户和组所拥有的最大权限

如果对有权限列表的文件执行chmod
setfacl -m:m:权限 file/directory
setfacl -m m:4 /public
default 对于对新建的文件或目录生效

eg:

[root@foundation38 mnt]# setfacl -m m:rwx file
[root@foundation38 mnt]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
group::r--
group:kiosk:rwx
mask::rwx

other::---
#####################################

默认权限
当需要在指定目录中新建文件或目录都对指定用户有特殊权限
setfacl -m d:u:user:权限 filename
默认权限对已有的还有目录本身不生效

eg:

[root@foundation38 mnt]# setfacl -m d:kiosk:rw westos
[root@foundation38 mnt]# setfacl -m u:kiosk:rw westos

[root@foundation38 westos1]# touch file{1..5}
[root@foundation38 westos1]# ls -ld file*
-rw-r--r-- 1 root root 0 Oct 31 21:36 file1
-rw-r--r-- 1 root root 0 Oct 31 21:36 file2
-rw-r--r-- 1 root root 0 Oct 31 21:36 file3
-rw-r--r-- 1 root root 0 Oct 31 21:36 file4
-rw-r--r-- 1 root root 0 Oct 31 21:36 file5
[root@foundation38 westos]# touch file{1..5}
[root@foundation38 westos]# ls -ld file*
-rw-rw-r--+ 1 root root 0 Oct 31 21:35 file1
-rw-rw-r--+ 1 root root 0 Oct 31 21:35 file2
-rw-rw-r--+ 1 root root 0 Oct 31 21:35 file3
-rw-rw-r--+ 1 root root 0 Oct 31 21:35 file4
-rw-rw-r--+ 1 root root 0 Oct 31 21:35 file5

#################################

[root@foundation38 westos]# touch test
[root@foundation38 westos]# vim test.sh

test.sh 里面填写内容为 echo 'hello,world'

[root@foundation38 westos]# chmod +x test.sh
[root@foundation38 westos]# pwd
/home/kiosk/Desktop/westos
[root@foundation38 westos]# /home/kiosk/Desktop/westos/test.sh
hello,world

###########延时--at######################

at time                ##time可设置为年月日小时分钟

步骤:

at 自设的时间

动作

Ctrl+d

[kiosk@foundation38 Desktop]$ find -name test.sh
./westos/test.sh
[kiosk@foundation38 Desktop]$ pwd
/home/kiosk/Desktop
[kiosk@foundation38 Desktop]$ at 22:01
at> /home/kiosk/Desktop/westos/test.sh
at> <EOT>
job 4 at Mon Oct 31 22:01:00 2016

[kiosk@foundation38 Desktop]$ at -l
5    Mon Oct 31 22:01:00 2016 a kiosk

[kiosk@foundation38 Desktop]$ mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/kiosk": 1 message 1 new
>N  1 kiosk                 Mon Oct 31 22:01  14/570   "Output from your job "
& 1
Message  1:
From kiosk@foundation38.ilt.example.com  Mon Oct 31 22:01:00 2016
Return-Path: <kiosk@foundation38.ilt.example.com>
X-Original-To: kiosk
Delivered-To: kiosk@foundation38.ilt.example.com
Subject: Output from your job        4
To: kiosk@foundation38.ilt.example.com
Date: Mon, 31 Oct 2016 22:01:00 +0800 (CST)
From: kiosk@foundation38.ilt.example.com (kiosk)
Status: R

hello,world

& q
Held 1 message in /var/spool/mail/kiosk
You have mail in /var/spool/mail/kiosk

####################################

at 设置黑白名单

vim /etc/at.allow##白名单允许的用户名列表

vim  /etc/at.deny##黑名单禁止的用户名列表

注释:当一个用户名同时出现在黑白名单上,默认执行白名单

#########定期管理#####################

crontab

crontab -l##列出文件

crontab -r##删除文件

crontab -e##编辑文件

vim /etc/cron.allow##白名单

vim /etc/cron.deny##黑名单

MM     hh    dd    mm   ww

分钟   小时  天   分钟   周

mm/2                     ##每隔2分钟

hh1-hh2                ##hh1到hh2时间段

hh1,hh2                ##hh1 hh2 2个时间点

[root@foundation38 cron.d]# echo '* * * * *  root touch /mnt/file{1..5}'>/etc/cron.d/westos
[root@foundation38 mnt]# watch -n 1 ls -l /mnt/
You have new mail in /var/spool/mail/kiosk

vim /usr/lib/tmpfiles.d/test.conf

d /run/test 0700 root root 5s

systemd-tmpfiles

-- create /usr/lib/tmpfiles.d/test.conf ##创建执行

-- clean /usr/lib/tmpfiles.d/test.conf ##撤销删除

###################################





















0 0
原创粉丝点击