When working with Windows file permissions, you've likely encountered strings that look like this:
S-1-5-21-3623811015-3361044348-30300820-1013
These are Security Identifiers (SIDs), the fundamental building blocks of Windows security. The format follows this pattern:
S-R-I-S-SA-SA-SA-RID
Where:
- S - Identifies the string as a SID
- R - Revision level (always 1 for Windows)
- I - Identifier authority (5 = NT Authority)
- S - Subauthority count
- SA - Subauthority values (domain or computer identifier)
- RID - Relative identifier (user or group specific)
When you use robocopy with the /COPY:S flag (copy security), you might notice SID strings appear differently between source and destination. This happens because:
robocopy /MIR C:\Windows\System32\tasks\ C:\temp\robocopyTasks\out\
robocopy /E /Copy:S /IS /IT C:\Windows\System32\tasks\ C:\temp\robocopyTasks\out\
The system attempts to translate SIDs to familiar account names (like "Administrators" or "SYSTEM"), but this translation depends on:
- Domain availability
- Local account database
- Security context of the robocopy operation
Here's how to convert between SIDs and account names using PowerShell:
# Convert SID to account name
$sid = New-Object System.Security.Principal.SecurityIdentifier "S-1-5-21-3623811015-3361044348-30300820-1013"
$sid.Translate([System.Security.Principal.NTAccount]).Value
# Convert account name to SID
$account = New-Object System.Security.Principal.NTAccount "DOMAIN\username"
$account.Translate([System.Security.Principal.SecurityIdentifier]).Value
When comparing permissions using icacls output, SIDs might appear differently. To get consistent SID formatting:
icacls file.txt /save perm.txt /t
# Then process perm.txt with consistent SID format
You can also use this VIM regex to find all SIDs in a file:
/S-\d-\d-\d\{2\}-\d\{10\}-\d\{10\}\-\d\{9\}\-\d\{4\}/
When copying files with robocopy:
# Recommended flags for complete security copy
robocopy source dest /MIR /COPYALL /SEC /R:1 /W:1 /LOG:copy.log
Key flags:
- /COPYALL - Copy all file info (equivalent to DATSOU)
- /SEC - Copy security (equivalent to /COPY:S)
- /MIR - Mirror directory tree (deletes extra files at destination)
When working with Windows file permissions using tools like icacls
or robocopy
, you'll often encounter security identifiers that look like this:
S-1-5-21-3623811015-3361044348-30300820-1013
These are Security Identifiers (SIDs), which uniquely identify security principals (users, groups, or computers) in Windows environments. The format follows a specific pattern:
S-R-I-SA-SA-...-RID
Let's examine a typical SID from your example:
S-1-5-21-3623811015-3361044348-30300820-1013
│ │ │ └───┬───────┴──────┬──────┴──┬───┴───┤
│ │ │ │ │ │ └── Relative Identifier (RID)
│ │ │ └─── Domain or Computer Identifier
│ │ └── Identifier Authority (5 = NT Authority)
│ └── Revision Level (always 1)
└── SID prefix
When you use robocopy
with the /COPY:S
flag (which copies security information), the tool preserves the original SIDs rather than resolving them to human-readable names. This happens because:
- The destination system might not have the same user accounts
- Some SIDs represent well-known identities (like SYSTEM or Administrators)
- It's more efficient for the copy operation
Here's a PowerShell script to convert SIDs to friendly names:
function Convert-SidToName {
param([string]$sidString)
try {
$sid = [System.Security.Principal.SecurityIdentifier]$sidString
return $sid.Translate([System.Security.Principal.NTAccount]).Value
}
catch {
return $sidString
}
}
# Example usage:
Convert-SidToName "S-1-5-21-3623811015-3361044348-30300820-1013"
Windows has several built-in SIDs that appear frequently:
S-1-5-18 Local System
S-1-5-32-544 Administrators group
S-1-5-32-545 Users group
S-1-5-11 Authenticated Users
If you need to maintain permissions across systems, consider these approaches:
# Method 1: Export and import using icacls
icacls source_folder /save permissions.txt
icacls destination_folder /restore permissions.txt
# Method 2: Use robocopy with account resolution
robocopy /COPYALL /SEC /ZB source destination
Here's how to handle SIDs in .NET applications:
using System;
using System.Security.Principal;
class Program {
static void Main() {
string sidString = "S-1-5-21-3623811015-3361044348-30300820-1013";
SecurityIdentifier sid = new SecurityIdentifier(sidString);
Console.WriteLine($"SID: {sid}");
Console.WriteLine($"Account: {sid.Translate(typeof(NTAccount))}");
Console.WriteLine($"Is Well-Known: {sid.IsWellKnown(WellKnownSidType.AccountAdministratorSid)}");
}
}