第三章 用户权限管理
权限类型
读:r=4 ;写:w=2;执行:x=1
[root@localhost ~]# ls -l 1.txt
-rw-r--r--. 1 root root 0 9月 10 17:02 1.txt
[root@localhost ~]#
-:文件类型
rw-:属主的权限
r--:属组的权限
r--:其他人的权限
.:权限得扩展
1:代表文件的链接
root:文件的属性
root:文件的属组
0:文件的大小
9月 10 17:02:文件最后的修改时间
1.txt:文件名和路径
更改权限
使用符号
u 用户;g 组;o 其他;r读;w写;x执行
语法:chmod 对象(u/g/0/a) 赋值符(+/-/=) 权限类型(r/w/x) 文件/目录
chmod u+x 授权文件
[root@localhost tanghl]# vi file.txt
[root@localhost tanghl]# ls -l
总用量 4
-rw-r--r--. 1 root root 82 9月 10 17:25 file.txt
[root@localhost tanghl]# chmod u+x file.txt
[root@localhost tanghl]# ls -l
总用量 4
-rwxr--r--. 1 root root 82 9月 10 17:25 file.txt
[root@localhost tanghl]# ./file.txt
Hello guys!
please type your name:tanghl
Hello #name guys!
[root@localhost tanghl]#
[root@localhost tanghl]# chmod u-x file.txt
[root@localhost tanghl]# ./file.txt
bash: ./file.txt: 权限不够
[root@localhost tanghl]# chmod ug=rw,o=r file.txt
[root@localhost tanghl]# ll file.txt
-rw-rw-r--. 1 root root 82 9月 10 17:25 file.txt
[root@localhost tanghl]#


使用数字
[root@localhost tanghl]# chmod 700 file.txt
[root@localhost tanghl]# ll file.txt
-rwx------. 1 root root 82 9月 10 17:25 file.txt
chown 该表文件用户拥有者
chown tanghl.tanghl file.txt
[root@localhost tanghl]# chmod 750 file.txt
[root@localhost tanghl]# ll
总用量 4
-rwxr-x---. 1 root root 82 9月 10 17:25 file.txt
[root@localhost tanghl]# chown tanghl.tanghl file.txt
[root@localhost tanghl]# ll
总用量 4
-rwxr-x---. 1 tanghl tanghl 82 9月 10 17:25 file.txt
chown user01 file.txt 只改表文件用户拥有者
[root@localhost tanghl]# chown user01 file.txt
[root@localhost tanghl]# ll
总用量 4
-rwxr-x---. 1 user01 tanghl 82 9月 10 17:25 file.txt
[root@localhost tanghl]#
chown .hr file.txt 只改变文件分组
[root@localhost tanghl]# chown .hr file.txt
[root@localhost tanghl]# ll
总用量 4
-rwxr-x---. 1 user01 hr 82 9月 10 17:25 file.txt
[root@localhost tanghl]#
查看代码
## 查看文件夹中文件的属性
[root@localhost tmp]# ll dir
总用量 0
-rw-r--r--. 1 root root 0 9月 10 18:02 file1.txt
-rw-r--r--. 1 root root 0 9月 10 18:02 file2.txt
-rw-r--r--. 1 root root 0 9月 10 18:02 file3.txt
## 查看文件夹的属性
[root@localhost tmp]# ll dir/ -d
drwxr-xr-x. 2 root root 57 9月 10 18:02 dir/
## 仅仅改变文件夹的用户拥有者
[root@localhost tmp]# chown tanghl.tanghl dir/
[root@localhost tmp]# ll
[root@localhost tmp]# ll dir/
总用量 0
-rw-r--r--. 1 root root 0 9月 10 18:02 file1.txt
-rw-r--r--. 1 root root 0 9月 10 18:02 file2.txt
-rw-r--r--. 1 root root 0 9月 10 18:02 file3.txt
[root@localhost tmp]# ll dir/ -d
drwxr-xr-x. 2 tanghl tanghl 57 9月 10 18:02 dir/
## 可以改变文件夹以及所属文件的属性
[root@localhost tmp]# chown tanghl.tanghl dir/ -R
[root@localhost tmp]# ll dir/
总用量 0
-rw-r--r--. 1 tanghl tanghl 0 9月 10 18:02 file1.txt
-rw-r--r--. 1 tanghl tanghl 0 9月 10 18:02 file2.txt
-rw-r--r--. 1 tanghl tanghl 0 9月 10 18:02 file3.txt
[root@localhost tmp]#
chgrp 只是改变数组
文件权限UGO实验
[root@localhost tmp]# groupadd jishu
[root@localhost tmp]# usermod -aG jishu user200
[root@localhost tmp]# id user200
用户id=1506(user200) 组id=1507(user200) 组=1507(user200),1509(jishu)
[root@localhost tmp]# touch file10.txt
[root@localhost tmp]# chmod 740 file10.txt
[root@localhost tmp]# ll file10.txt
-rwxr-----. 1 root root 0 9月 10 18:21 file10.txt
[root@localhost tmp]#
[root@localhost tmp]# chown user100.jishu file10.txt
[user100@localhost tmp]$ ll file10.txt
-rwxr-----. 1 user100 jishu 0 9月 10 18:21 file10.txt
[user100@localhost tmp]$ ll file10.txt
-rwxr-----. 1 user100 jishu 0 9月 10 18:21 file10.txt
[user100@localhost tmp]$ vim file10.txt
[user100@localhost tmp]$ cat file10.txt
echo 1111dyy
echo 1111dyy
echo 1111dyy
echo 1111dyy
echo 1111dyy
echo 1111dyy
echo 1111dyy
echo 1111dyy
echo 1111dyy
[user100@localhost tmp]$ ll file10.txt
-rwxr-----. 1 user100 jishu 117 9月 10 18:30 file10.txt
[user100@localhost tmp]$ ./file10.txt
1111dyy
1111dyy
1111dyy
1111dyy
1111dyy
1111dyy
1111dyy
1111dyy
1111dyy
[user100@localhost tmp]$
1 user100 jishu 117 9月 10 18:30 file10.txt
[user100@localhost tmp]$ su user200
密码:
[user200@localhost tmp]$ ll file10.txt
-rwxr-----. 1 user100 jishu 117 9月 10 18:30 file10.txt
[user200@localhost tmp]$ vim file10.txt
[user200@localhost tmp]$
[user200@localhost tmp]$ ./file10.txt
bash: ./file10.txt: 权限不够
[user200@localhost tmp]$ su user300
密码:
[user300@localhost tmp]$ ll file10.txt
-rwxr-----. 1 user100 jishu 117 9月 10 18:30 file10.txt
[user300@localhost tmp]$ cat file10.txt
cat: file10.txt: 权限不够
[user300@localhost tmp]$
浙公网安备 33010602011771号