[英]Linux file permissions(in-depth) - numeric to string notation, and vice versa; additional file-permissions
我想出了如何將符號rwx部分讀取/轉換為421個八進制部分的方法,這非常簡單。 但是當涉及到特殊字符時,我感到非常困惑。 我們知道-r-xr --- wx轉換為0543,但是-r-sr --- wt或-r-xr --- wt轉換為什么?
我相信在用戶執行許可下有x,s,S。對於組執行許可也有x,s,S。然后所有其他用戶執行許可有x,t,T。這些是什么意思,以及它們如何轉換八進制表示法。 我猜它與0421中的0位置有關嗎?
從我的課堂筆記中可以看出,5543轉換為-r-sr --- wt。 然后,示例問題-rS-wsrw-轉換為6536,除了它希望我們固定第二個位置(5)以便將其正確轉換。
我搜索並搜索了很多內容,但令人驚訝的是這些特殊字符找不到任何東西。
在Web上進行深入搜索之后,我找到了有關了解Linux文件權限的鏈接 , 該鏈接對其進行了詳細描述:
s-這表示 setuid / setgid權限。 未設置為顯示在權限顯示的特殊權限部分,而是按所有者或組權限的讀取部分表示。
t-這表示粘性位權限。 未設置在權限顯示的特殊權限部分中顯示,而是在所有用戶權限的可執行部分中表示。
Setuid / Setgid的特殊權限
--- setuid / setguid權限用於告訴系統以具有所有者權限的所有者身份運行可執行文件。
---請謹慎使用權限中的setuid / setgid位。 如果您錯誤地將setuid / setgid位置1,將權限分配給root擁有的文件,則可以打開系統進行入侵。
---您只能通過顯式定義權限來分配setuid / setgid位。 setuid / setguid位的字符為s。
粘性位特殊權限
---黏貼位在共享環境中非常有用,因為當將其分配給目錄的權限時,它會對其進行設置,因此只有文件所有者才能重命名或刪除該文件。
---您只能通過顯式定義權限來分配粘性位。 粘性位的字符是t。
從數值(1/2/4421)轉換為符號(rwx / s / t)的邏輯:
編輯:
第一個數字表示所有者權限; 第二個代表組權限; 最后一個數字代表所有其他用戶的權限。 這些數字是rwx字符串的二進制表示形式。
r = 4
w = 2
x = 1
--->粘性位可以使用chmod命令進行設置,並且可以使用八進制模式1000或符號t(setuid位已使用s)進行設置。 例如,要在目錄/ usr / local / tmp上添加該位,可以鍵入chmod 1777 /usr/local/tmp
。
---> setuid和setgid位通常是通過chmod命令設置的,方法是將setuid的高階八進制數字設置為4或將setgid設置為 2 。 chmod 6711 file
將同時設置setuid和setgid位(4 + 2 = 6),從而使文件對所有者(7)可讀/寫/可執行,並可由組(前1個)和其他用戶(第二個1)執行。
s --- The setuid bit when found in the user triad; the setgid bit when found in the group
triad; it is not found in the others triad; it also implies that x is set.
S --- Same as s, but x is not set; rare on regular files, and useless on folders.
t --- The sticky bit; it can only be found in the others triad; it also implies that x is
set.
T --- Same as t, but x is not set; rare on regular files, and useless on folders.
s,S,t和T值始終附加在“其他用戶組”權限符號之前。 因此,符號的第一個字母表示附加到字符串的s,S,t或T值。 接下來的3個字母是通常的權限。
您有關文件權限的問題/示例:
1. -r-sr---wt = 5543, first 5(s set for user = 4 + t set for others = 1),
second 5(r=4,s=1), third 4(r = 4), and last, fourth 3(w=2, t = 1).
2. -r-S-wsrw- = 6436, first 6(S set for user = 4 + s set for group = 2),
second 5(r=4, x=0, since S don't account for x),
third 3(w = 2, s results in x = 1), and last, fourth 6(r=4,w=2).
如果您需要實際的位,可以在stat.2
手冊頁上找到它們(格式設置為代碼,以便於閱讀):
The following mask values are defined for the file type of the
st_mode field:
S_IFMT 0170000 bit mask for the file type bit field
S_IFSOCK 0140000 socket
S_IFLNK 0120000 symbolic link
S_IFREG 0100000 regular file
S_IFBLK 0060000 block device
S_IFDIR 0040000 directory
S_IFCHR 0020000 character device
S_IFIFO 0010000 FIFO
...
The following mask values are defined for the file mode component of
the st_mode field:
S_ISUID 04000 set-user-ID bit
S_ISGID 02000 set-group-ID bit (see below)
S_ISVTX 01000 sticky bit (see below)
S_IRWXU 00700 owner has read, write, and execute permission
S_IRUSR 00400 owner has read permission
S_IWUSR 00200 owner has write permission
S_IXUSR 00100 owner has execute permission
S_IRWXG 00070 group has read, write, and execute permission
S_IRGRP 00040 group has read permission
S_IWGRP 00020 group has write permission
S_IXGRP 00010 group has execute permission
S_IRWXO 00007 others (not in group) have read, write, and
execute permission
S_IROTH 00004 others have read permission
S_IWOTH 00002 others have write permission
S_IXOTH 00001 others have execute permission
這些位在/usr/include/uapi/linux/stat.h
頭文件中定義:
#ifndef _UAPI_LINUX_STAT_H
#define _UAPI_LINUX_STAT_H
#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
#define S_IFMT 00170000
#define S_IFSOCK 0140000
#define S_IFLNK 0120000
#define S_IFREG 0100000
#define S_IFBLK 0060000
#define S_IFDIR 0040000
#define S_IFCHR 0020000
#define S_IFIFO 0010000
#define S_ISUID 0004000
#define S_ISGID 0002000
#define S_ISVTX 0001000
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001
#endif
#endif /* _UAPI_LINUX_STAT_H */
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.