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—第一個字符得位置讀得權限位
???????? 第二個字符得位置寫得權限位
???????? 第三個字符得位置執(zhí)行得權限位
R????? 4
W???? 2
X?????? 1
-?????? 0
【文件】權限詳細說明
如果此前沒有創(chuàng)建oldboy,可以執(zhí)行下面命令,而不是需要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)
如果此前沒有創(chuàng)建oldboy,可以執(zhí)行下面命令,而不需要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?#<==在根下創(chuàng)建測試目錄oldboy。
[root@oldboy?~]#?echo?"echo?oldboyLinux"?>/oldboy/[if !vml]
[endif]test.sh?#<==
生成腳本文件[if !vml]
[endif]test.sh,內(nèi)容是打印oldboyLinux字符串。
[root@oldboy?~]#?cat?/oldboy/[if !vml]
[endif]test.sh?#<==
查看腳本[if !vml]
[endif]test.sh內(nèi)容。
echo?oldboyLinux
[root@oldboy?~]#?chmod?+x?/oldboy/[if !vml]
[endif]test.sh?#<==
加執(zhí)行權限,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權限有兩種表現(xiàn)形式:
[if !supportLists]1、 [endif]數(shù)字表示法
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
安全權限臨界點:
文件不想被修改被執(zhí)行:644
[root@quyunlong/oldboy]# ll
total 4
-rw-r--r-- 1 root oldboy 7 Mar 21 10:26
test.sh
[root@quyunlong/oldboy]#
目錄不想被修改(刪除移動創(chuàng)建)被執(zhí)行:(進入):755
博客:寫博客。。。服務器得博客目錄和文件得權限,防止被惡意篡改。
企業(yè)案例:網(wǎng)站文件被惡意修改了。。。。。打開網(wǎng)站后又彈窗廣告(不是你得網(wǎng)站得)
用戶打開網(wǎng)站,報警。
原因:權限設置不到。Chmod –R
777 目錄?開發(fā)人員習慣。
控制默認權限得東西?? umask?
[root@quyunlong/oldboy]#
umask
0022
[root@quyunlong/oldboy]#
創(chuàng)建文件默認嘴的權限為666(-rw-rw-rw-),
[if !vml]

[endif]
666
022? -
644默認權限
當umask中存在奇數(shù)位得時候,就在計算完畢,奇數(shù)位加1
基于文件:默認權限規(guī)則
從666計算
Umask都為偶數(shù)??? 默認權限用減法
Umask 有奇數(shù)?????? 默認權限用減法??? 然后奇數(shù)位加1
基于目錄:默認權限規(guī)則
從777計算
默認權限用減法
Linux系統(tǒng)特殊權限位知識
9位基礎權限
還有3位特殊權限位
Suid位:
Suid(setuid)位通過S字符標識,
[if !vml]

[endif]

[if !vml]

4?????? 2?????? 1,加和放在基礎權限數(shù)字得前面
修改方法:
[if !vml]

[endif]
工作中有啥用?
[if !vml]

[endif]

解決方案:
[if !supportLists]1、 [endif]備份
[if !supportLists]2、 [endif]找到被修改得文件
[if !supportLists]3、 [endif]批量刪除或者替換
[if !supportLists]4、 [endif]找到文件來源,被篡改來源,并優(yōu)化調(diào)整。
亡羊補牢
5、寫總結(jié)????? 故障報告。
