Replace all child object permissions with inheritable permissions from this object là gì

I am trying to enable "replace all child object permission entries with inheritable permission entries from this object" method using PowerShell, below is my Script

Replace all child object permissions with inheritable permissions from this object là gì

$ProfileDir = 'C:\Users\' $Profiles = Get-ChildItem $ProfileDir \ Select-Object -ExpandProperty Name ForEach ($X in $Profiles) { $Profile = $ProfileDir + $X Write-Host "Starting $Profile" $Acl = Get-Acl $Profile $Acl.SetAccessRuleProtection($false, $true) (Get-Item $Profile).SetAccessControl($Acl) $Permissions = (Get-Acl $Profile).Access | Where-Object { (-not $_.isInherited) -and $_.IdentityReference -like "domain\*" } ForEach ($Y in $Permissions) { $Acl.AddAccessRule($Y) } (Get-Item $Profile).SetAccessRule($Acl) (Get-Acl $Profile).Access }

Replace all child object permissions with inheritable permissions from this object là gì

asked Apr 14 at 19:16

Replace all child object permissions with inheritable permissions from this object là gì

5

Below is the script I have created and it worked as expected.

Thank you for your suggestions and help. To replace all child objects, I have used Get-ChildItem with -recurse and it worked.

$objName = (Get-CimInstance -ClassName Win32_ComputerSystem).UserName.Split("\")[1] $objDir = "C:\Users\$objName\" $objUser = (Get-CimInstance -ClassName Win32_ComputerSystem).UserName $objAccount = New-Object System.Security.Principal.NTAccount($objUser) $objRule = $objUser,"FullControl","ContainerInherit,ObjectInherit","None","Allow" $objFileSec = New-Object System.Security.AccessControl.FileSecurity $objAccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($objRule) $objFileSec.SetOwner($objAccount) $objAclSec = Get-Acl $objDir $objAclSec.SetAccessRuleProtection($true,$true) $objAclSec.PurgeAccessRules($objAccount) $objAclSec.SetAccessRule($objAccessRule) Get-ChildItem -Path $objDir | Set-Acl -AclObject $objAclSec $objAclSec.Access | Format-Table Pause

answered Apr 21 at 13:01

Replace all child object permissions with inheritable permissions from this object là gì

Not the answer you're looking for? Browse other questions tagged windows powershell permissions filesystems acl or ask your own question.

I have a share drive folder that people from all over the company are right-click moving files into it so another department can process them.  As we know, the right-click move function will retain the NTFS permissions of the folder it came from, but this is causing the department that needs to process them to not be able to access them (until I go in and manually replace the child objects inheritable permissions).  The "easy" answer to this is to instruct people to copy/paste then delete, but if you worked with the staff I work with, you would understand why I am hoping to avoid that method if possible.

So here is my thought... is there a script I could create/run in say a scheduled task that would periodically run the Security>Advanced>Replace all child object permission entries with inheritable permission entries from this object?  

Or a better idea?  I was thinking a tool like TerraCopy that might have options you can configure so that the NTFS permissions are NOT retained during a move (which it does not appear Terracopy can do).  I found this downloadable tool (https://helgeklein.com/setacl/), but I have never heard of it/them and not sure if I should trust it.

Chào các bạn, trong bài viết này chúng ta sẽ cùng tiếp tục tìm hiểu về chủ đề phân quyền NTFSNTFS Permission trên Windows Server 2012 nhé. Cũng như tiếp tục Series Tự Học MCSA 2012 tại website ‘Cuongquach.com‘.

Contents

  • 1. NTFS Permission là gì?
  • 2. Đặc điểm của NTFS permission
    • 2.1 Standard permission
    • 2.2 Special Permission

Khi xây dựng File server để user lưu trữ dữ liệu thì ta có nhu cầu thiết lập các quyền hạn, chức năng liên quan đến dữ liệu. Microsoft cung cấp cho ta bộ quyền NTFS (NTFS Permission) để thiết lập quyền trên dữ liệu đối với user

Yêu cầu: dữ liệu phải được lưu trữ trên phân vùng có định dạng NTFS. Vậy nếu phân vùng đang ở định dạng FAT32 thì ta có thể dùng lệnh sau để chuyển từ định dạng FAT32 sang NTFS (lưu ý chuyển từ NTFS sang FAT, FAT32 dùng lệnh này không được).

start -> run -> cmd convert [drive]: /FS:NTFS

Ví dụ:

convert D: /FS:NTFS

Tạo Folder bất kì, chọn Properties, Tab Security: đây là giao diện của bộ quyền NTFS (còn gọi là ACL: Access Control List).

Replace all child object permissions with inheritable permissions from this object là gì
ACL

Giao diện gồm 2 phần:

  • Đối tượng cần phân quyền.
  • Các permission tương ứng.

2. Đặc điểm của NTFS permission

NTFS permission gồm có các đặc tính sau:
Tính thừa kế: quyền của folder cha thế nào thì khi tạo folder con sẽ có quyền tương tự.
Tác động lên cả file và folder.
Tác động lên Network Access (truy cập qua mạng) và Local Access.

NTFS permission gồm 2 nhóm chính:

  • Standard permission
  • Special permission

2.1 Standard permission

Standard permission gồm 6 bộ quyền:

Read: cho phép user đọc nội dung file.
List folder contents: liệt kê nội dung folder (user có thể mở folder để xem có các file, sub folder nào trong đó).
Read and execute: Có thể đọc nội dung các file ( file *.doc, ppt. xls v.v) và thực thi các file nếu file đó là chương trình (.exe, .bat v.v).
* Khi phân quyển user thì ta nên cho cả 3 quyền này.
Write: chỉnh sửa, tạo mới dữ liệu.
+ Nếu user có quyền write trên file thì user có thể chỉnh sửa dữ liệu, nếu là folder thì có thể tạo mới các đối tượng trong folder, chép dữ liệu vào folder. Nhưng không thể xóa các đối tượng.
Modify: bằng các quyền ở trên gộp lại và thêm quyền delete ( đọc, chỉnh sửa, xóa các đối tượng).
Full control: gồm
+ Modify
+ Quyền change permission (là quyền được cho phép thiết lập lại các bộ quyền).
+ Quyền: Take Ownership

2.1.1 Ví dụ về standard permission

Tạo 4 user: KT1, KT2 thuộc group KeToan. NS1, NS2 thuộc group NhanSu.
Vào ổ đĩa C tạo folder Data. Trong Data tạo 3 folder Chung, KeToan, NhanSu, và 2 file t1.txtt2.txt (nội dung tùy ý). Mỗi folder con  tạo 1 file text .txt (cũng nội dung tùy ý).

Replace all child object permissions with inheritable permissions from this object là gì
Folder

Yêu cầu: thiết lập quyền cho các folder.

  • Data: cho group KeToan, NhanSu có quyền Read and execute.
  • Chung: tất cả có quyền full.
  • Ketoan: chỉ group KeToan có quyền full, cấm group NhanSu.
  • Nhansu: chỉ group NhanSu có quyền full, cấm group KeToan.

Lưu ý: khi thực hiện phân quyền phải thực hiện từ folder cha di xuống.
Do folder Data chỉ cho group KeToan và NhanSu truy cập nên ta phải xóa group Users (Users đại diện cho tất cả user, được kế thừa từ ổ C), chọn Edit

Replace all child object permissions with inheritable permissions from this object là gì

Chọn Users -> Remove.
Replace all child object permissions with inheritable permissions from this object là gì

Xuất hiện thông báo: Không thể remove group Users vì group này đang chịu quyền thừa kế từ folder cha
Replace all child object permissions with inheritable permissions from this object là gì

Để gỡ bỏ quyền thừa kế: Chọn Advance
Replace all child object permissions with inheritable permissions from this object là gì

Chọn Disable inheritance
Replace all child object permissions with inheritable permissions from this object là gì

Xuất hiện bảng thông báo:
Remove all inherited permission from this object: xóa tất cả các quyền thừa kế, các đối tượng trong ACL kể cả các group hệ thống (Creater Owner, System, Administrators).
Convert inherited permission into ….: giữ lại các đối tượng ở folder cha và folder con, nếu folder cha có group Ketoan thì folder con cũng có group Ketoan (khuyên nên dùng).
Replace all child object permissions with inheritable permissions from this object là gì

=> Remove thành công.

Folder Data: add group KeToan, NhanSu và cho quyền Read and Execute.

Replace all child object permissions with inheritable permissions from this object là gì

Replace all child object permissions with inheritable permissions from this object là gì

Replace all child object permissions with inheritable permissions from this object là gì

Folder Chung thừa kế các quyền và các đối tượng thì folder Data.
Replace all child object permissions with inheritable permissions from this object là gì

Chọn Full Controll cho Group Ketoan, NhanSu
Replace all child object permissions with inheritable permissions from this object là gì

Folder Ketoan: chọn Full Control cho Ketoan.

Cách cấm group NhanSu (2 cách)
– Không đưa đối tượng vào bảng ACL (bỏ quyền thừa kế và xóa group NhanSu).
– Cho quyển deny đối tượng

Lưu ý: (hạn chế deny cho đối tượng group vì nếu xảy ra trường hợp: “NS1” có nhu cầu vào folder Ketoan làm việc thì ta phải cấp quyền Read cho NS1 nhưng do group NhanSu bị deny nên deny ưu tiên hơn => NS1 không có quyền. Còn dùng cách trên thì chỉ cần add thêm NS1 rồi cấp quyền Read là xong ). Folder Nhansu làm tương tự .

Replace all child object permissions with inheritable permissions from this object là gì

Cách Test quyền cho các user

> Cách 1 (thực tế thường dùng): Chọn folder KeToan -> Tab security -> Advance -> Tab Effective Access

Replace all child object permissions with inheritable permissions from this object là gì

Select a user: gõ vào KT1 -> view effective access

Replace all child object permissions with inheritable permissions from this object là gì

Gõ vào User: NS1

Replace all child object permissions with inheritable permissions from this object là gì

> Cách 2: Đăng nhập vào từng user để test (!!!).

Các lưu ý khi phân quyền:
– Phân quyền từ folder cha đến folder con.
– Nếu 1 user nằm ở 2 group, 1 group bị Deny, và 1 group có quyền Read thì user đó sẽ bị quyền Deny.
– Nếu 1 user nằm ở 2 group thì group nào có quyền lớn hơn thì user sẽ có quyền đó ( group quyền Read và group quyền Modify thì user có quyền Modify).

Tình huống 1:
Đối với Folder Ketoan, group Ketoan có quyền full control, vì thế các user trong group kế toán có thể xóa tài nguyên của nhau. Ta có nhu cầu KT1 không được phép chỉnh sửa, xóa tài nguyên của người khác, chỉ được chỉnh sửa, xóa tài nguyên của mình tạo ra. Để phân quyền chi tiết như thế thì ta phải dùng Special permission.
Special permission  là sự chi tiết hóa các quyền của Standar permission.
Giao diện Special permission: Properties folder Data -> tab security -> Advance, chọn group Ketoan Edit

Replace all child object permissions with inheritable permissions from this object là gì
Chọn Show basic permission (đây là giao diện của special permission)

Replace all child object permissions with inheritable permissions from this object là gì
14 quyền special permission

2.2 Special Permission

Special Permission gồm 14 quyền:

Full control: toàn quyền, giống Full control của standar permission.
Traverse folder/ execute file: Quyền thực thi file + quyền đi vào folder, ta chỉ vào được khi dùng lệnh “cd”. VD: cd C:\Data nếu ta sử dụng quyền Traverse folder/ execute cho folder Data).
List folder / Read data: Đi vào thư mục và đọc dữ liệu trên thư mục đó.
Read Attributes: đọc thuộc tính folder và file ( Read only, Hiden v.v).
Read Attributes: đọc thuộc tính mở rộng (Archive, Encrypt).
Create file/ Write data: tạo file và ghi, chỉnh sửa dữ liệu.
Create folder/ Append data:
– Cho phép tạo folder
– Ghi ghi dữ liệu vào phía cuối file ( ghi nối tiếp) , chứ không xóa, chình sửa phần dữ liệu  sẵn có (chỉ áp dụng cho file).
Write Attributes: Cho phép thay đổi các thuộc tính của file, folder (read-only, hiden).
Write Extended Attributes: Cho phép chỉnh sửa các thuộc tính mở rộng của file, folder. Thuộc tính mở rộng được xác định bởi các chương trình (program), các chương trình khác nhau có các thuộc tính mờ rộng khác nhau.
Delete Subfolders and files: Xóa các folder con và các file.
Delete: Cho phép xóa tài nguyên (folder, subfolder, file).
Change permission: Cho phép thay đổi các quyền hạn đối vối file, folder.
Read permission: cho phép user, group thấy các quyền hạn mà ta đã cấu hình.
Take Ownership: Cho phép lấy quyền sở hữu file, folder của người khác.
Ngoài ra ta còn có 7 thành phần có thể liên kết với 14 bộ quyền special permission

Replace all child object permissions with inheritable permissions from this object là gì
Applies to

This folder only: chỉ áp dụng quyền vào folder này ( các subfolder, file không bị áp đặt)
This folder, subfolders, files: áp lên folder, các folder con và các file trong các folder.
This folder and subfolders: áp lên folder và subfolders.
This folder and files: áp lên folder và các file ( subfolder không bị áp quyền).
Subfolder and files only: chỉ subfolder và các file bên trong mới bị áp đặt quyền.
Subfolder only: chỉ có quyền trên subfolder.
Files only: chỉ áp đặt quyền trên các file.

Để thực hiện như ví dụ trên, ta chỉ cần cho group Ketoan quyền như hình:

Replace all child object permissions with inheritable permissions from this object là gì

Trên folder Ketoan, KT1 tạo file KT1.txt. Kiểm tra ta thấy KT2 chỉ có thể đọc KT1.txt

Replace all child object permissions with inheritable permissions from this object là gì

Đối với KT1 thì lại có toàn quyền trên folder, file do nó tạo ra. Vậy tại sao lại như thế ?
Trước tiên ta phải tìm hiểu về Group định danh:
– Là group quy định điều kiện để lấy member (thành viên).
– Bao gồm:
Users (mặc định khi user tạo ra là thuộc group này)
Administrators.
System: group định danh hệ thống (mặc định full control).
Creator Owner: chứa member là những user tạo ra tài nguyên (ai tạo ra tài nguyên thì người đó thuộc nhóm Creator Owner trên tài nguyên đó)

Group Creator Owner có quyền full control.Vì KT1 tạo ra KT1.txt => KT1 có quyền full control trên KT1.txt. Nếu mất Creator Owner thì không thể phân quyền.

Tình huống 2:
KT1 xóa hết các đối tượng trong tab security trong file KT1.txt

Replace all child object permissions with inheritable permissions from this object là gì

Administrator muốn đọc được KT1.txt thì phải làm cách nào ??

Administrator có 1 quyền rất đặc biệt là: Take ownership (chiếm sở hữu trên tài nguyên), chỉ có group administrators  mới có.

Administrator Properties: KT1.txt -> Advance

Replace all child object permissions with inheritable permissions from this object là gì

Bấm Change: Chọn group, user muốn chiếm sở hữu.

Lưu ý: Chỉ có Group Administrator có quyền take ownership (các user khác nếu có quyền full control cũng không thể take ownership) bởi vì hệ thống có 1 policy:

Computer configuration -> Windows Setting -> Security Setting -> Local policy -> User right assignment Take ownership of files or other object (mặc định Administrator).

Cách áp permission của 1 folder lên mọi tài nguyên bên trong nó.

Properties: folder KeToan -> Tab security -> Advance: Check vào Replace all child object permission entries with inheritable permission entries from this object.

Mình xin kết thúc bài viết “Tự học MCSA 2012 NTFS Permission“. Mình đã cố gắng nói những gì chi tiết nhất. Nếu có thắc mắc các bạn xin để lại câu hỏi.