linux檔案許可權問題

redhouser發表於2012-11-12

關於Linux下檔案許可權:

問題1,使用者自己的檔案許可權為007時是否可寫?


[root@bnet95 ~]# groupadd test
[root@bnet95 ~]# useradd -g test t
[root@bnet95 ~]# id t
uid=505(t) gid=506(test) groups=506(test)
[root@bnet95 ~]# su - t
[t@bnet95 ~]$ pwd
/home/t
[t@bnet95 ~]$ touch file1
[t@bnet95 ~]$ ln file1 ln_file1
[t@bnet95 ~]$ ln -s file1 lns_file1

[t@bnet95 ~]$ ls -rlt
total 0
-rw-r--r-- 2 t test 0 Sep 29 09:09 ln_file1
-rw-r--r-- 2 t test 0 Sep 29 09:09 file1
lrwxrwxrwx 1 t test 5 Sep 29 09:49 lns_file1 -> file1

[t@bnet95 ~]$ stat file1
  File: `file1'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: fd00h/64768d    Inode: 4325382     Links: 2
Access: (0644/-rw-r--r--)  Uid: (  505/       t)   Gid: (  506/    test)
Access: 2013-09-29 09:09:13.000000000 +0800
Modify: 2013-09-29 09:09:13.000000000 +0800
Change: 2013-09-29 09:47:07.000000000 +0800

[t@bnet95 ~]$ stat ln_file1
  File: `ln_file1'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: fd00h/64768d    Inode: 4325382     Links: 2
Access: (0644/-rw-r--r--)  Uid: (  505/       t)   Gid: (  506/    test)
Access: 2013-09-29 09:09:13.000000000 +0800
Modify: 2013-09-29 09:09:13.000000000 +0800
Change: 2013-09-29 09:47:07.000000000 +0800
==硬連結許可權與原始檔相同,指向相同的inode

 


[t@bnet95 ~]$ stat lns_file1
  File: `lns_file1' -> `file1'
  Size: 5               Blocks: 0          IO Block: 4096   symbolic link
Device: fd00h/64768d    Inode: 4325383     Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (  505/       t)   Gid: (  506/    test)
Access: 2013-09-29 09:50:01.000000000 +0800
Modify: 2013-09-29 09:49:58.000000000 +0800
Change: 2013-09-29 09:49:58.000000000 +0800
==>軟連結許可權為777,指向不同的inode

[t@bnet95 ~]$ chmod 007 file1
[t@bnet95 ~]$ ls -lrt
total 0
-------rwx 2 t test 0 Sep 29 09:09 ln_file1
-------rwx 2 t test 0 Sep 29 09:09 file1
lrwxrwxrwx 1 t test 5 Sep 29 09:49 lns_file1 -> file1
==>硬連結檔案,指向相同inode及資料塊,修改一個檔案的許可權屬性會同時修改另外一個檔案(許可權等資訊儲存在inode中)。


[t@bnet95 ~]$ export LANG=en_US
[t@bnet95 ~]$ ls >file1
-bash: file1: Permission denied
==〉使用者自己的檔案也受007許可權限制,無法讀寫。


[t@bnet95 ~]$ chmod a+w file1
[t@bnet95 ~]$ ls >file1

 

 

問題2,root自己的檔案許可權為007時是否可寫?

[root@bnet95 tmp]# ls > file1
[root@bnet95 tmp]#
[root@bnet95 tmp]# export LANG=en_US
[root@bnet95 tmp]# ls -lrt  file*
-rw-r--r-- 1 root root 551 Sep 29 10:11 file1

[root@bnet95 tmp]# chmod 007 file1
[root@bnet95 tmp]# ls -lrt  file*
-------rwx 1 root root 551 Sep 29 10:11 file1
[root@bnet95 tmp]# ls >file1

[root@bnet95 tmp]# more file1
BinPwoR5vc
c
file1
gconfd-bocnet
gconfd-root
hsperfdata_oracle
keyring-S5AMfl
mapping-bocnet
mapping-liujian
mapping-oracle
mapping-root
scim-panel-socket:0-bocnet
scim-panel-socket:0-oracle
scim-panel-socket:0-root
scim-panel-socket22.11.97.243:0-liujian
scim-panel-socket22.11.97.243:0-oracle
scim-panel-socket22.11.97.243:0-root
scim-panel-socket22.11.97.243:2-oracle
scim-panel-socket22.11.99.74:0-oracle
scim-panel-socket22.11.99.99:0-bocnet
scim-panel-socket22.11.99.99:0-oracle
scim-panel-socket22.11.99.99:0-root
ssh-kFwnP13993
ssh-URWOw14519

==〉root使用者對所有檔案有寫許可權,甚至不受007限制。

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/18922393/viewspace-748998/,如需轉載,請註明出處,否則將追究法律責任。

相關文章