更改特定使用者對 RedHat 中特定資料夾和子資料夾/檔案的權限(唯讀)?

更改特定使用者對 RedHat 中特定資料夾和子資料夾/檔案的權限(唯讀)?

問題是關於 RedHat 中的使用者權限。如何授予特定使用者唯讀權限以讀取特定資料夾及其子資料夾和檔案?

我該怎麼做?

我已經嘗試過:chmod a+r -R folder但它不起作用 - 許可仍然被拒絕。

所以,情況是,我在 root 下工作,我有:

  • 用戶1
  • 用戶2

我需要為 user2 提供唯讀資料夾以及 user1 的所有檔案和子資料夾的機會。

我怎樣才能做到這一點?

我已經嘗試過:chmod user2 r -R user1但它也不起作用。

它仍然具有被拒絕的許可。

答案1

假設 user1 是該資料夾的擁有者,並且對其具有完全權限,則最好透過 chown 該資料夾由 user1 擁有並由 user2 所屬的群組擁有來處理該資料夾。像下面這樣的東西會起作用:

# usermod -a -G somegroup user2
# ls -l | grep ExampleFolder
drwxr-xr-x 2 root root    4096 Dec 25 23:32 ExampleFolder
# chown -R user1:somegroup ExampleFolder
# ls -l | grep ExampleFolder
drwxr-xr-x 2 user1 somegroup    4096 Dec 25 23:32 ExampleFolder

現在,user2 僅具有對ExampleFolder 的讀取和執行權限。只需對該群組執行 chmod 即可進一步變更權限。

user2@linux:/opt$ cd ExampleFolder/
user2@linux:/opt/ExampleFolder$ ls
user2@linux:/opt/ExampleFolder$ touch somefile
touch: cannot touch `somefile': Permission denied

相關內容