Linux基础权限 是9个字符。
33694335 -rw-r--r-- 1 root root 369 Mar 20 17:53 5
33694321 -rw-r--r-- 1 root root 21 Mar 20 11:13 a.txt
33694322 -rw-r--r-- 1 root root 37 Mar 20 11:21 b.txt
-rw-r--r—
-rw-r--r—
-rw-r--r—
分3组:
前三个字符是表示用户(属主)权限位 user 用户
中三个字符是表示用户组权限 group 用户组
后三个字符是其它用户权限位 others 其他用户
同一组得三个字符权限也是有位置:
r—第一个字符得位置读得权限位
第二个字符得位置写得权限位
第三个字符得位置执行得权限位
R 4
W 2
X 1
- 0
【文件】权限详细说明
如果此前没有创建oldboy,可以执行下面命令,而不是需要usermod命令
Useradd oldboy–g incahome
[root@quyunlong~]# groupdadd incahome
-bash: groupdadd: command not found
[root@quyunlong~]# groupadd incahome
[root@quyunlong~]# useradd oldboy
[root@quyunlong~]# usermod -gincahome
oldboy
[root@quyunlong~]# id oldboy
uid=1002(oldboy) gid=1003(incahome)
groups=1003(incahome)
测试准备:
incahome(家、组)
oldboy 家庭男主人,用来代表用户(User)角色,是文件的所有者
oldgirl 女主人(和所有者oldboy属于相同组,oldboy的家人)用来代表用户组incahome的角色
test 其他人 其他(others)人,用来代表其他用户角色
[root@oldboyedu ~]# groupadd incahome
[root@oldboyedu ~]# useradd oldboy
useradd: user 'oldboy' already exists
[root@oldboyedu ~]# usermod -g incahome oldboy
[root@oldboyedu ~]# id oldboy
uid=1000(oldboy) gid=1004(incahome) groups=1004(incahome),1000(oldboy)
如果此前没有创建oldboy,可以执行下面命令,而不需要usermod命令。
[root@oldboyedu ~]# useradd oldboy -g
incahome
[root@oldboyedu ~]# useradd oldgirl -g
incahome
useradd: user 'oldgirl' already exists
[root@oldboyedu ~]# id oldgirl
uid=1001(oldgirl) gid=1001(oldgirl)
groups=1001(oldgirl)
[root@oldboyedu ~]# usermod -g incahome
oldgirl
[root@oldboyedu ~]# id oldgirl
uid=1001(oldgirl) gid=1004(incahome)
groups=1004(incahome)
[root@oldboyedu ~]# useradd test
useradd: user 'test' already exists
[root@oldboy ~]# mkdir -p /oldboy #<==在根下创建测试目录oldboy。
[root@oldboy ~]# echo "echo oldboyLinux" >/oldboy/[if !vml]
[endif]test.sh #<==
生成脚本文件[if !vml]
[endif]test.sh,内容是打印oldboyLinux字符串。
[root@oldboy ~]# cat /oldboy/[if !vml]
[endif]test.sh #<==
查看脚本[if !vml]
[endif]test.sh内容。
echo oldboyLinux
[root@oldboy ~]# chmod +x /oldboy/[if !vml]
[endif]test.sh #<==
加执行权限,chmod的使用可见本章后文。
[root@oldboy ~]# ls -l /oldboy/[if !vml]
[endif]test.sh #<==
查看授权后的权限属性。
-rwxr-xr-x. 1 root root 17 Apr 30 09:55 /oldboy/[if !vml]
[endif]test.sh
[if !vml]
[endif]
[if !vml]
[endif]
权限修改:
Linux权限有两种表现形式:
[if !supportLists]1、 [endif]数字表示法
R 4
W 2
X 1
- 0
实际得权限表示就是将没3位相加即可
Rwxr-xr-x 755
Rwx 7
r-x 5
r-x 5
[if !vml]
2、 [endif]字符表示法
U
G
[root@oldboyedu /oldboy]# chmod u=rw,g=rw,o=rx[if !vml]
[endif]test.sh
[root@oldboyedu /oldboy]# ls -l
total 4
-rw-rw-r-x 1 root root 12 Oct 7 22:16[if !vml]
[endif]test.sh
[root@oldboyedu /oldboy]# chmod u-rw,u+x,g-w,g+x,o-r,o+w[if !vml]
[endif]test.sh
[root@oldboyedu /oldboy]# ls -l
total 4
---xr-x-wx 1 root root 12 Oct 7 22:16[if !vml]
[endif]test.sh
[root@oldboyedu /oldboy]# chmod 153[if !vml]
[endif]test.sh
[root@oldboyedu /oldboy]# ls -l
total 4
---xr-x-wx 1 root root 12 Oct 7 22:16[if !vml]
[endif]test.sh
[root@oldboyedu /oldboy]# chmod a=x[if !vml]
[endif]test.sh
[root@oldboyedu /oldboy]# ls -l
total 4
---x--x--x 1 root root 12 Oct 7 22:16[if !vml]
[endif]test.sh
[endif]
修改文件属性得永固和组
Chown 用户.用户组 文件 这里得点可以用:替换。
Chown 用户 文件
Chown .用户组 文件
[root@oldboyedu /oldboy]# chown oldboy[if !vml]
[endif]test.sh
[root@oldboyedu /oldboy]# ls -l
total 4
---x--x--x 1 oldboy root 12 Oct 7 22:16[if !vml]
[endif]test.sh
[root@oldboyedu /oldboy]# chown .incahome[if !vml]
[endif]test.sh
[root@oldboyedu /oldboy]# ls -l
total 4
---x--x--x 1 oldboy incahome 12 Oct 7 22:16[if !vml]
[endif]test.sh
[root@oldboyedu /oldboy]# chown root:root[if !vml]
[endif]test.sh
[root@oldboyedu /oldboy]# ls -l
total 4
---x--x--x 1 root root 12 Oct 7 22:16[if !vml]
[endif]test.sh
安全权限临界点:
文件不想被修改被执行:644
[root@quyunlong/oldboy]# ll
total 4
-rw-r--r-- 1 root oldboy 7 Mar 21 10:26
test.sh
[root@quyunlong/oldboy]#
目录不想被修改(删除移动创建)被执行:(进入):755
博客:写博客。。。服务器得博客目录和文件得权限,防止被恶意篡改。
企业案例:网站文件被恶意修改了。。。。。打开网站后又弹窗广告(不是你得网站得)
用户打开网站,报警。
原因:权限设置不到。Chmod –R
777 目录 开发人员习惯。
控制默认权限得东西 umask
[root@quyunlong/oldboy]#
umask
0022
[root@quyunlong/oldboy]#
创建文件默认嘴的权限为666(-rw-rw-rw-),
[if !vml]
[endif]
666
022 -
644默认权限
当umask中存在奇数位得时候,就在计算完毕,奇数位加1
基于文件:默认权限规则
从666计算
Umask都为偶数 默认权限用减法
Umask 有奇数 默认权限用减法 然后奇数位加1
基于目录:默认权限规则
从777计算
默认权限用减法
Linux系统特殊权限位知识
9位基础权限
还有3位特殊权限位
Suid位:
Suid(setuid)位通过S字符标识,
[if !vml]
[endif]
[if !vml]
4 2 1,加和放在基础权限数字得前面
修改方法:
[if !vml]
[endif]
工作中有啥用?
[if !vml]
[endif]
解决方案:
[if !supportLists]1、 [endif]备份
[if !supportLists]2、 [endif]找到被修改得文件
[if !supportLists]3、 [endif]批量删除或者替换
[if !supportLists]4、 [endif]找到文件来源,被篡改来源,并优化调整。
亡羊补牢
5、写总结 故障报告。