하프! 리디렉션된 폴더/홈 디렉토리에 대한 권한 악몽을 물려받았습니다.

하프! 리디렉션된 폴더/홈 디렉토리에 대한 권한 악몽을 물려받았습니다.

내 새 고용주는 수백 명의 사용자를 위해 폴더 리디렉션을 설정했는데, 이를 설정한 사람은 자신이 무엇을 하고 있는지 실제로 알지 못했습니다. 결과적으로,리디렉션된 폴더/홈 디렉터리에 대한 권한에 대한 모범 사례따르지 않았습니다.

사람들이 리디렉션된 폴더 위치에 액세스할 수 있도록 하는 솔루션은 대신 루트 디렉터리("홈") Full Control에 권한(물론 "공유" 권한이 아닌 NTFS 권한)을 적용 Everyone하고 이를 루트 아래의 모든 하위 폴더 및 파일에 전파하는 것이었습니다. .

무엇이 잘못될 수 있나요? CEO가 자신의 My Documents폴더에 기밀 정보를 가지고 있거나 누군가가 CryptoWall에 감염되어 다른 모든 사람의 파일을 암호화하는 것과는 다릅니다 . 오른쪽?

어쨌든 이제 CryptoWall 감염이 제거되고 백업이 복원되었으므로 많은 사람들이 현재 권한을 덜 끔찍한 것으로 교체하기를 원하며 저는 여러 번에 걸쳐 권한 대화 상자를 클릭할 필요가 없습니다. 백 폴더.

PowerShell은 어떻게 이 문제를 해결하고 삶을 다시 살 가치 있게 만들 수 있습니까?

답변1

JScott 덕분에System.Security.Principal... 클래스나 메서드 등을 언급하기 위해 일부 PowerShell은 여러 하위 폴더의 ACL을 사용자 홈 디렉터리에 적합한 ACL로 대체합니다.

$Root = "Path to the root folder that holds all the user home directories"

$Paths = Get-ChildItem $Root | Select-Object -Property Name,FullName

$DAAR = New-Object system.security.accesscontrol.filesystemaccessrule("MyDomain\Domain Admins","FullControl","ContainerInherit, ObjectInherit","None","Allow")
#Domain Admin Access Rule.

$SysAR = New-Object system.security.accesscontrol.filesystemaccessrule("SYSTEM","FullControl","ContainerInherit, ObjectInherit","None","Allow")
#SYSTEM Access Rule.

foreach ($Folder in $Paths)
{

    Write-Host "Generating ACL for $($folder.FullName) ... "
    #For error handling purposes - not all folders will map to a user of the exact same name, this makes them easier to handle when viewing the output.

    $ACL = New-Object System.Security.AccessControl.DirectorySecurity
    #Creates a blank ACL object to add access rules into, also blanks out the ACL for each iteration of the loop.

    $objUser = New-Object System.Security.Principal.NTAccount("MyDomain\​"+$folder.name)
    #Creating the right type of User Object to feed into our ACL, and populating it with the user whose folder we're currently on.

    $UserAR = New-Object system.security.accesscontrol.filesystemaccessrule( $objuser ,"FullControl","ContainerInherit, ObjectInherit","None","Allow")
    #Access Rule for the user whose folder we're dealing with during this iteration.

    $acl.SetOwner($objUser)
    $acl.SetAccessRuleProtection($true, $false)
    #Change the inheritance/propagation settings of the folder we're dealing with

    $acl.SetAccessRule($UserAR)
    $acl.SetAccessRule($DAAR)
    $acl.SetAccessRule($SysAR)

    Write-Host "Changing ACL on $($folder.FullName) to:"
    $acl | fl
    #For error handling purposes - not all folders will map to a user of the exact same name, this makes them easier to handle when viewing the output.

    Set-Acl -Path $Folder.Fullname -ACLObject $acl

}

답변2

이전 답변이 작동하지 않습니다만약에홈 폴더/리디렉션된 폴더는 "사용자에게 독점 권한 부여"로 설정되었습니다. 왜냐하면 이 옵션을 선택하면권장되지 않는 것, SYSTEM 및 THE USER만이 폴더에 대한 권한을 갖습니다. 그런 다음 폴더의 소유권을 가져오지 않으면 권한을 변경할 수 없습니다(관리자라도).

이는 소유권을 가지지 않고 이 문제를 해결하는 방법입니다. 이는 2단계 프로세스입니다.

ICACLS를 실행하여 폴더 및 하위 폴더의 권한을 수정하는 powershell 스크립트를 만듭니다.

PSexec를 실행하여 Powershell 스크립트를 시작합니다.

다음에서 가져오고 수정함: https://mypkb.wordpress.com/2008/12/29/how-to-restore-administrators-access-to-redirected-my-documents-folder/

1 powershell 스크립트 생성/복사/도용(PS 3.0 이상 필요)

#ChangePermissions.ps1
# CACLS rights are usually
# F = FullControl
# C = Change
# R = Readonly
# W = Write

$StartingDir= "c:\shares\users"   ##Path to root of users home dirs
$Principal="domain\username"    #or "administrators"
$Permission="F"

$Verify=Read-Host `n "You are about to change permissions on all" `
"files starting at"$StartingDir.ToUpper() `n "for security"`
"principal"$Principal.ToUpper() `
"with new right of"$Permission.ToUpper()"."`n `
"Do you want to continue? [Y,N]"

if ($Verify -eq "Y") {

foreach ($FOLDER in $(Get-ChildItem -path $StartingDir -directory -recurse)) {

$temp = $Folder.fullname
CACLS `"$temp`" /E /P `"${Principal}`":${Permission} >$NULL
#write-host $Folder.FullName 
}
}
  1. PSEXEC를 실행하면 SYSTEM 계정으로 동작하므로 SYSTEM과 사용자만 접근할 수 있는 폴더에 대한 권한을 변경할 수 있습니다. PSexec를 설치하고 실행합니다.https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

명령줄에서:

psexec -s -i powershell -noexit "& 'C:\Path\To\ChangePermissions.ps1'"

관련 정보