導航:首頁 > 文件類型 > linux文件的許可權末尾點

linux文件的許可權末尾點

發布時間:2023-05-21 19:44:58

『壹』 linux操作系統文件訪問許可權詳解

一直以root登陸使用linux的人來說很少有許可權被拒這種概念,但某些時候又深受許可權拒絕困擾。
知道為什麼很多程序中需要使用getuid(),setuid()?為什麼以普通許可權登陸的用戶不能進入/root,為什麼在/目錄下執行ls -l後可以顯示root的信息,但ls /root -al卻是許可權不夠?為什麼有些文件夾可以繼續創建文件,但就是不能ls?等等,相信看了此文就能明白。
主要是學習筆記,不足之處請指正。
CentOS 5.4 [testc@xxx opt]$ uname -a Linux xxx 2.6.18-164.el5xen #1 SMP Thu Sep 3 04:47:32 EDT 2009 i686 i686 i386 GNU/Linux
一、口令文件1,格式存儲文件/etc/passwd,格式如下:root:x:0:0:root:/root:/bin/bash aaa:x:501:501:bj, bj, 8111111,136000111:/home/aaa:/bin/bash用戶名:加密密碼:用戶ID:組ID:注釋:工作目錄:shell:
默認情況是第一行的格式;注釋欄位可以自行修改,用逗號隔開,如第二行格式,這主要是給finger命令使用時可解析。
可以vi /etc/passwd修改,但為了保證其格式的正確性,請用vipw命令編譯此文件。
sh-3.2# finger aaa Login: aaa Name: bj Directory: /home/aaa Shell: /bin/bash Office: bj, 8111111 Home Phone: 136000111 Never logged in. No mail. No Plan.
2,編程實例
/*getpwnam_pwuid.c*/ #include #include #include
int main(void)
{ //struct passwd *pwd = getpwnam("aaa");struct passwd *pwd = getpwuid(501);if(pwd == NULL)
{ printf("err.\n");return 1;}
printf("name:%s\n", pwd->pw_name);printf("passwd:%s\n", pwd->pw_passwd);printf("description:%s\n", pwd->pw_gecos);printf("uid:%d\n", pwd->pw_uid);printf("gid:%d\n", pwd->pw_gid);printf("dir:%s\n", pwd->pw_dir);printf("shell:%s\n", pwd->pw_shell);
return 0;}
sh-3.2# gcc getpwnam_pwuid.c -o app sh-3.2# ./app name:aaa passwd:x description:bj, bj, 8111111,136000111 uid:501 gid:501 dir:/home/aaa shell:/bin/bash
二、組文件1,格式存儲文件/etc/group,格式如下root:x:0:root bin:x:1:root,bin,daemon aaa:x:501:組名:加密密碼:組ID:指向的各用戶名
2,改變文件uid和gid.
sh-3.2# pwd /root/study sh-3.2# ls -al -rw-r——r—— 1 root root 397 10-11 03:23 test.c
chgrp 改變所屬組ID,當然只有root許可權才可以修改。
sh-3.2# chgrp aaa test.c sh-3.2# ls -al -rw-r——r—— 1 root aaa 397 10-11 03:23 test.c
這個aaa就是新組名,其在/etc/group中,可以通過adser aaa自行添加sh-3.2# cat /etc/group root:x:0:root bin:x:1:root,bin,daemon daemon:x:2:root,bin,daemon.
gdm:x:42:sabayon:x:86:plmtest:x:500:aaa:x:501:
chown 改變用戶ID或組ID sh-3.2# chown aaa:aaa test.c sh-3.2# ls -al -rw-r——r—— 1 aaa aaa 397 10-11 03:23 test.c
3,編程實例
/*getgrnam.c*/ #include #include
int main(int argc, char *argv[])
{ if(argv[1] == NULL)
{ printf("input error.\n");return 1;}
struct group *gp = getgrnam(argv[1]);if(gp == NULL)
{ printf("err.\n");return 1;}
printf("name:%s\n", gp->gr_name);printf("psswd:%s\n", gp->gr_passwd);printf("gid:%d\n", gp->gr_gid);
int i;for(i = 0; gp->gr_mem[i] != NULL; i++)
{ printf("group name:%s\n", gp->gr_mem[i]);}
return 0;}
sh-3.2# gcc getgrnam.c -o app sh-3.2# ./app bin name:bin psswd:x gid:1 group name:root group name:bin group name:daemon 4,文件許可權不細講了sh-3.2# ls -al總計 483984 drwxr-x—— 13 root root 4096 02-22 00:01 . drwxr-xr-x 32 root root 4096 02-21 21:15 ……
-rw-r——r—— 1 root root 464023491 10-25 22:33 3.3.005-080425.tgz -rw—— 1 root root 9346 02-21 23:16 .bash_history -rw-r——r—— 1 root root 24 2007-01-06 .bash_logout -rw-r——r—— 1 root root 191 2007-01-06 .bash_profile -rw-r——r—— 1 root root 176 2007-01-06 .bashrc drwxrwxrwx 10 1000 users 4096 08-23 20:16 cflow-1.3 -rw-r——r—— 1 root root 759691 08-23 20:13 cflow.tar.gz -rw-r——r—— 1 root root 100 2007-01-06 .cshrc -rwxr-xr-x 1 root root 582 11-11 21:48 delete_M.sh -rw-r——r—— 1 root root 2518 11-11 20:25 .dir_colors
主要是最左邊一列:drwxr-x——10個字元,最左邊是文件類型,-默認為普通文件;d:目錄文件;l符號鏈接……
後面9個,3個一組共三組,分別表示所屬用戶uid的許可權;所屬組或者附屬組gid的許可權;其它許可權。
三個字元分別是讀、寫、執行許可權讀4,寫2, 執行1
所以chmod 777 test.c,提升到讀、寫、執行許可權。
5,組許可權操作實例此節演示相同組的成員之間共享資源,即不同uid但相同gid的用戶共享同一組的資源。
為了方便起見,我同時開了兩個終端。
"sh-3.2#"以root許可權登陸的shell /bin/sh "[testa@xxx root]"以testa用戶登陸的shell
註:下文提到的「用戶」是指/etc/passwd里定義的通過終端登陸的用戶(此文即以下增加的三個賬號名)。
sh-3.2# useradd testa sh-3.2# useradd testb sh-3.2# useradd testc
sh-3.2# tail -f /etc/passwd -n 4 sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin testa:x:500:500::/home/testa:/bin/bash testb:x:501:501::/home/testb:/bin/bash testc:x:502:502::/home/testc:/bin/bash
再開一個終端登陸testa,之前那個終端保持。
sh-3.2# su testa [testa@xxx root]$ id uid=500(testa) gid=500(testa) groups=500(testa)
[testa@xxx home]$ ls -al總計 28 drwxr-xr-x 5 root root 4096 02-21 22:52 . drwxr-xr-x 32 root root 4096 02-21 21:15 ……
drwx—— 3 testa testa 4096 02-21 22:56 testa drwx—— 3 testb testb 4096 02-21 22:48 testb drwx—— 3 testc testc 4096 02-21 22:52 testc
[testa@xxx home]$ cd testb bash: cd: testb: 許可權不夠
通過root修改testb目錄許可權為770,即當前uid或者gid相同的用戶均有讀寫執行許可權。
sh-3.2# cd /home/ sh-3.2# chmod 770 testb
[testa@xxx home]$ ls -al總計 28 drwxr-xr-x 5 root root 4096 02-21 22:52 . drwxr-xr-x 32 root root 4096 02-21 21:15 ……
drwx—— 3 testa testa 4096 02-21 22:56 testa drwxrwx—— 3 testb testb 4096 02-21 22:48 testb (here modify)
drwx—— 3 testc testc 4096 02-21 22:52 testc
[testa@xxx home]$ cd testb bash: cd: testb: 許可權不夠[testa@xxx root]$ id uid=500(testa) gid=500(testa) groups=500(testa)
此時雖然開放了testb的所屬組許可權,但用戶testa的gid=500(testa) groups=500(testa),它還不屬於testb組。
下面修改testa的gid為testb(或者增加其附屬組groups值為testb)
sh-3.2# usermod -G testb testa (增加用戶testa的附屬組testb)
sh-3.2# id testa uid=500(testa) gid=500(testa) groups=500(testa),501(testb)
此時testa終端需要重新登下,使剛才更改生效[testa@xxx root]$ exit exit [root@xxx ~]# su testa [testa@xxx root]$ id uid=500(testa) gid=500(testa) groups=500(testa),501(testb)
[testa@xxx root]$ cd /home/ [testa@xxx home]$ ls -al總計 28 drwxr-xr-x 5 root root 4096 02-21 22:52 . drwxr-xr-x 32 root root 4096 02-21 21:15 ……
drwx—— 3 testa testa 4096 02-21 22:56 testa drwxrwx—— 3 testb testb 4096 02-21 22:48 testb drwx—— 3 testc testc 4096 02-21 22:52 testc [testa@xxx home]$ cd testb [testa@xxx testb]$ pwd /home/testb
以上是增加了用戶testa的附屬組testb,使其對於屬於testb組的資源有了訪問許可權。
下面再使用newgrp切換用戶testa的gid.
[testa@xxx testb]$ id uid=500(testa) gid=500(testa) groups=500(testa),501(testb)
[testa@xxx testb]$ newgrp testb [testa@xxx testb]$ id uid=500(testa) gid=501(testb) groups=500(testa),501(testb)
此時testa用戶的gid已改為501(testb)。
組之前的關系在文件/etc/group sh-3.2# tail -f /etc/group -n 4 sabayon:x:86:testa:x:500:testb:x:501:testa (最後一列:組內用戶列表。即組testb里包含testa,testa屬於testb組,大概就這意思吧……)
testc:x:502:
雖然知道控制組關系的文件,但不能直接修改些文件,否則執行newgrp時會出現"抱歉"錯誤提示。
當然root用戶許可權是無限制的,它訪問文件時不需要進行許可權檢查。
三、相關系統調用getuid();getgid();int setuid(uid_t uid);int setgid(gid_t gid);
只有超級用戶或者需要設置的uid和當前用戶的uid一致才可以設置,否則返回-1,置errno = EPERM, errno可以通過strerror()翻譯。
其它:[testa@xxx home]$ su testa [testa@xxx home]$ sudo touch aa
testa is not in the sudoers file. This incident will be reported.
以root許可權vim /etc/sudoers增加testa ALL=(ALL) ALL
參考:APUE2E,1.8, 4.4, 8.11

『貳』 linux文件屬性結尾的.是什麼意思 比如-rwxr-xr-x.

-rwxr-xr-x是linux特的許可權屬性三個為一組如下

-rwx版r-xr-x

擁有者所在的組權其他的組
r:表示只讀
w:表示可以寫
x:表示可以執行
上面的意思是:自己可以讀寫執行該文件,所在的用戶組里的用戶可以讀和執行該文件,而其他的用戶組里的用戶也可以讀和執行該文件

『叄』 linux734是什麼許可權

首先我們講講linux 許可權問題。

linux許可權從左至右,第一位數字代表文件所有者的許可權,第二位數字代表同組用戶的許可權,第三位數字代表其他用戶的許可權。

而具體的許可權是由數字來表示的。

讀取的許可權等於4,用r表示;

寫入的許可權等於2,用w表示;

執行的許可權等於1,用x表示;

我們可以通過4、2、1的組合,得到以下幾種許可權:

0(沒有許可權);

4(讀取許可權);

5(4+1 | 讀取+執行);

6(4+2 | 讀取+寫入);

7(4+2+1 | 讀取+寫入+執行)

以755為例: 第一位7等於4+2+1,rwx,所有者具有讀取、寫入、執行許可權;

第二位5等於4+1+0,r-x,同組用戶具有讀取、執行許可權但沒有寫入許可權;

第三位5,同上,也是r-x,其他用戶具有讀取、執行許可權但沒有寫入許可權。

下面列出常用的linux文件許可權:

444 r--r--r-- 所有組只有讀取許可權

555 r -xr -xr -x 所有組都是讀取和執行許可權

666 rw-rw-rw- 所有組只有讀取和寫入許可權

777 rwxrwxrwx 所有組都有讀取和寫入和執行許可權

600 rw------- 第一個組有讀取和寫入許可權

644 rw-r--r-- 所有組都有寫入和讀取許可權,第一個組有讀取和寫入許可權

700 rwx------ 第一個組有讀寫執行許可權其它沒有許可權

744 rwxr--r-- 第一個組有讀寫執行許可權 第二第三有讀取和寫入許可權

寫了這么多 可能有錯 自己檢查下吧。就是自己組合下!今天就講到這里!

755 rwxr-xr-x

基本上就是全部開放讀寫執行操作許可權……

一個文件有三個許可權,分別是讀、寫和執行,它們對應的數分別是4、2和1。

如果某個用戶只有讀許可權沒有寫和執行許可權當然就是4,如果三個如果有讀和執行許可權就是5(4+1)……所以有全部許可權就是7了。

而一個文件或文件夾面對的用戶分三類:所屬用戶、所屬用戶的組其他用戶以及組外用戶。

所以777三個數字就是對應這三個用戶對象全部都有讀、寫、執行許可權。

如果是所屬用戶有全部許可權,組員有讀和執行許可權,而組外用戶只有讀許可權,那數字應該就是754……

『肆』 liunx 許可權後面的點是什麼意思

開啟了SELinux功孝伍能的Linux系統才會有這個點。
那個點表示文件帶有「SELinux的安全上下文」。
CentOS7默認是開啟SELinux的,所以會有這個點,
如果關閉SELinux,然後再創建文件,新創建的文件就不會再有這個點了,
但是以前創建的文御蔽件本來有這鎮慎州個點的還會顯示這個點(雖然SELinux不起作用了)

『伍』 linux文件或目錄中,許可權後面的數字1或2是什麼意思

Linux文件許可權字元串後面的數字是表示這個文件的硬連接文件數目,如果是1就表示這個文件沒有硬連接文件,如果是2就表示這個文件的硬連接是1個,如果是3就表示這個文件的硬連接是2個,如果是4就表示這個文件的硬連接數目是3個,以此類推。

閱讀全文

與linux文件的許可權末尾點相關的資料

熱點內容
文件領導簽字在哪裡 瀏覽:239
電腦保存文件是點哪裡 瀏覽:689
word07圖片框 瀏覽:359
跨境付app現在支持哪些國家 瀏覽:647
手機mid文件 瀏覽:929
華碩筆記本升級bios找不到文件 瀏覽:399
編程和電腦哪個更適合孩子 瀏覽:718
xls壓縮文件怎麼設置 瀏覽:423
微信眨眼小女孩 瀏覽:207
cad2010安裝文件 瀏覽:379
編程上什麼學 瀏覽:364
美版s7升級70移動4g 瀏覽:112
金融數據包含哪些 瀏覽:240
尼爾應用程序錯誤 瀏覽:157
淘特app如何助力 瀏覽:472
cad文件有木馬 瀏覽:459
多頁文件怎樣改變字體 瀏覽:145
16燈搖搖棒的程序 瀏覽:705
作業成本相關數據哪裡找 瀏覽:826
買鞋有什麼推薦的app 瀏覽:239

友情鏈接