linux系统内有档案有三种身份 u:拥有者 g:群组 o:其他人
这些身份对于文档又有下面权限 可以用ls -l 文件名 查看权限信息
r:读权限,用户可以读取文档的内容,如用cat,more查看w:写权限,用户可以编辑文档
x:该目录具有可以被系统执行的权限
s root执行
s权限是'使用root用户执行'的权限。在这里使用 chmod +s filename 和 chmod -s filename 来更改文件的s权限。文件的s权限位区分大小写,如果是大写的S就是s位没有生效,如果是小写的s就是s位已经生效。如果用户本身没有文件的x权限,就直接加上了s权限就会导致s权限位失效,显示为大写S。S权限只能使用在二进制文件上。
Linux下的 passwd 命令是任何人都可以用的,最起码可以用来修改自己的密码。但是我们的密码又是存在 /etc/shdown 里的,如果我们修改了自己的密码那么必要要修改这个文件。然而这个文件的权限是 ----------. 也就是任何人都不能修改。那么 passwd 这个命令就可以让普通用户临时提升权限,从而修改这个文件,所以 passwd 这个命令文件的权限就包含了s权限。
[root@localhost ~]# ls -l /etc/shadow
----------. 1 root root 2104 Sep 29 12:37 /etc/shadow
[root@localhost ~]# ls -l /usr/bin/passwd
-rwsr-xr-x. 1 root root 27832 Jun 10 2014 /usr/bin/passwd
T 禁止删除
t权限是‘不可删除’权限,就是说即使某用户拥有这个文件的rwx权限,可以随意修改文件内容,但是就是不能删除,甚至不能修改文件名,只有root才行。t权限也可以直接用 chmod +t filename 和 chmod -t filename 来修改。
[testUserT@localhost shell]$ chmod +t test_t.py[testUserT@localhost shell]$ ls -l
total 16
-rw-r--r--. 1 root root 67 Sep 29 12:22 test_a.py
-rw-r--r--. 1 root root 55 Sep 29 11:42 test_i.py
-rw-r--r--. 1 root root 55 Sep 29 12:19 test_s.py
-rw-r--r-T. 1 testUserT testUserT 61 Sep 29 12:34 test_t.py
[testUserT@localhost shell]$ echo "hello,world" > test_t.py
[testUserT@localhost shell]$ echo "hello,world" >> test_t.py
[testUserT@localhost shell]$ rm test_t.py
rm: cannot remove ‘test_t.py’: Permission denied
[testUserT@localhost shell]$ mv test_t.py test_tt.py
mv: cannot move ‘test_t.py’ to ‘test_tt.py’: Permission denied
a 只追加
[root@localhost shell]# chattr +a test_a.py
[root@localhost shell]# lsattr test_a.py
-----a---------- test_a.py
[root@localhost shell]# echo "hello,world" > test_a.py #不能将数据直接覆盖
bash: test_a.py: Operation not permitted
[root@localhost shell]# echo "hello,world" >> test_a.py #可以将数据追加到后面
如果我们试图使用vim等文本编辑器去修改具有a权限的文件的话,在保存的时候就会提示没有相应的权限 E212: Cannot open file for writing ,我这里是Vim给出的警告。
i 不可修改
i权限是一个完全不可修改的权限,即使这个文件权限是777也必须要取消掉i权限才可以修改。我们还是使用 lsattr filename 查看i权限设置,然后使用 chattr +i filename 和 chattr -i filename 设置a权限。
[root@localhost shell]# lsattr test_i.py---------------- test_i.py
[root@localhost shell]# chattr +i test_i.py
[root@localhost shell]# lsattr test_i.py
----i----------- test_i.py
#删除,覆盖,追加都不行
[root@localhost shell]# echo "hello,world" > test_i.py
bash: test_i.py: Permission denied
[root@localhost shell]# echo "hello,world" >> test_i.py
bash: test_i.py: Permission denied
[root@localhost shell]# rm test_i.py
rm: remove regular file ‘test_i.py’? y
rm: cannot remove ‘test_i.py’: Operation not permitted