---
title: Install Certificates for gMSA Accounts - PowerShell Scripts
description: PowerShell scripts to install certificates in LocalMachine store for gMSA accounts. Handles CNG and CSP key storage. Compatible with PowerShell 5.1 and 7. Includes self-signed certificate creation, PFX import, PEM conversion, and automatic ACL management.
---

# Install Certificates for gMSA Accounts

<sup><span class="nodinite-new-badge">New 7.x</span></sup>

When using [Group Managed Service Accounts (gMSA)][gMSA] with <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> v7, you must manually provision and manage the [secret-encryption certificate][Secret Management] in the **LocalMachine** certificate store, because <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> can't auto-generate it in a gMSA's user profile. This page provides PowerShell scripts (compatible with PowerShell 5.1 and PowerShell 7) for common certificate installation scenarios.

<aside aria-label="Note" class="nodinite-note nodinite-note--note">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-note"></i> Note</p>
<div class="nodinite-note__content"><p>This page is about the certificate that encrypts secrets. The TLS/HTTPS certificate of the <a href="https://docs.nodinite.com/core-services/overview/">Core Services</a> web sites is a different certificate: you identify it by subject in <a href="https://docs.nodinite.com/install-and-update/getting-started/version-7/install-nodinite-v7-steps/04-servers/#core-host-tls">Step 4: Servers - Core host Configuration</a>, and the CLI finds and binds it at every install and update.</p></div>
</aside>

## Understanding Certificate Requirements for gMSA

<aside aria-label="Important" class="nodinite-note nodinite-note--important">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-message-exclamation"></i> Important</p>
<div class="nodinite-note__content"><p>These scripts must be run with elevated (Administrator) privileges. The gMSA account itself cannot install certificates in the LocalMachine store.</p></div>
</aside>

Unlike traditional service accounts where <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> auto-generates certificates, gMSA accounts require manual certificate management:

|Requirement|Details|  
|---|---|  
|**Certificate Store**|`Cert:\LocalMachine\My` (not user profile)|  
|**Hash Algorithm**|**SHA-256 or higher** (SHA-1 not supported)|  
|**Key Length**|Minimum 2048-bit RSA (4096-bit recommended for production)|  
|**Exportable**|Yes — mark as an exportable certificate for backup and disaster recovery|  
|**Private Key Access**|gMSA account must have Read permission on private key file|  
|**Subject Name**|Recommended: Match gMSA account name (e.g., CN=NodiniteProdSvc)|  

<aside aria-label="Note" class="nodinite-note nodinite-note--note">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-note"></i> Note</p>
<div class="nodinite-note__content"><p><strong>Why LocalMachine Store?</strong> gMSA accounts don't have user profiles, so they cannot access the Personal (CurrentUser) certificate store. All certificates for gMSA accounts must be installed in <code>Cert:\LocalMachine\My</code> with appropriate ACL permissions granted to the gMSA account.</p></div>
</aside>
<aside aria-label="Important" class="nodinite-note nodinite-note--important">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-message-exclamation"></i> Important</p>
<div class="nodinite-note__content"><p><strong>CNG vs CSP Key Storage:</strong> Modern Windows uses <strong>CNG (Crypto Next Generation)</strong> which stores private keys in <code>ProgramData\Microsoft\Crypto\Keys\</code>, while legacy certificates use <strong>CSP (Cryptographic Service Provider)</strong> storing keys in <code>ProgramData\Microsoft\Crypto\RSA\MachineKeys\</code>. The scripts below automatically detect which storage type your certificate uses and set permissions on the correct location. If you see "private key not found" errors with other scripts, it's usually because they only check one location.</p></div>
</aside>

## Understanding Certificate Storage Architecture

The diagram below shows how certificates are installed in LocalMachine store and how gMSA accounts access private keys:

<div class="mermaid">
graph TB
    ADMIN["fa:fa-user-shield Administrator<br/>(Elevated PowerShell)"]
    CERT["fa:fa-certificate Certificate<br/>LocalMachine My store"]
    CNG["fa:fa-key CNG Private Key<br/>ProgramData Crypto Keys"]
    CSP["fa:fa-key CSP Private Key<br/>ProgramData Crypto RSA MachineKeys"]
    ACL["fa:fa-lock ACL Permissions<br/>(Read Access)"]
    GMSA["fa:fa-user-gear gMSA Account<br/>(Service Identity)"]
    SERVICE["fa:fa-gear Nodinite Services<br/>(IIS or Windows Service)"]
    ADMIN --> CERT
    CERT --> CNG
    CERT --> CSP
    CNG --> ACL
    CSP --> ACL
    ACL --> GMSA
    GMSA --> SERVICE
    style ADMIN fill:#2678BD,color:#fff
    style CERT fill:#FFD525
    style CNG fill:#93d16d
    style CSP fill:#93d16d
    style ACL fill:#FFD525
    style GMSA fill:#93d16d
    style SERVICE fill:#2678BD,color:#fff
</div>

*This diagram shows the certificate installation flow: an administrator installs the certificate in the `LocalMachine\My` store (yellow), which creates a private key in either the CNG or the CSP location (green). ACL permissions (yellow) grant the [gMSA][] account (green) Read access, so the [Core Services][] and agents (blue) can use the certificate for [secret encryption][Secret Management].*

## Certificate Installation Options

You can install certificates for gMSA accounts using:

1. **Self-Signed Certificates** - For testing/development environments (see script below)
2. **PFX Import** - For certificates from a Certificate Authority; PFX files bundle the certificate and private key
3. **PEM Import** - For OpenSSL or Linux-based PKI certificates provided in PEM format

All methods require granting the gMSA account Read access to the private key file.

---

## Option 1: Create and Install a Self-Signed Certificate

Use this script when you need a self-signed certificate for testing or non-production environments. This script handles both CNG (modern) and CSP (legacy) private key storage locations:

```powershell
# PowerShell script to create and install a self-signed certificate for gMSA
# Compatible with PowerShell 5.1+ and PowerShell 7+
# Must be run with Administrator privileges

param(
    [string]$Subject = "CN=NodiniteProdSvc",
    [string]$gMSA = "CONTOSO\NodiniteProdSvc$",
    [int]$KeyLength = 2048,
    [int]$ValidityYears = 3
)

# Ensure running as Administrator
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
    throw "This script must be run as Administrator."
}

# Create self-signed certificate in LocalMachine store
$notAfter = (Get-Date).AddYears($ValidityYears)
Write-Host "Creating self-signed certificate $Subject (KeyLength=$KeyLength) valid until $notAfter..." -ForegroundColor Cyan

$cert = New-SelfSignedCertificate `
    -Subject $Subject `
    -KeyAlgorithm RSA `
    -KeyLength $KeyLength `
    -KeyExportPolicy Exportable `
    -CertStoreLocation "Cert:\LocalMachine\My" `
    -Provider "Microsoft Software Key Storage Provider" `
    -HashAlgorithm "SHA256" `
    -NotAfter $notAfter

if (-not $cert) {
    throw "Certificate creation failed."
}

Write-Host "Certificate created successfully!" -ForegroundColor Green
Write-Host "  Thumbprint: $($cert.Thumbprint)" -ForegroundColor Yellow
Write-Host "  Subject: $($cert.Subject)" -ForegroundColor Yellow
Write-Host "  Expires: $($cert.NotAfter)" -ForegroundColor Yellow

# Wait for key file to be fully written
Start-Sleep -Seconds 1

# Locate private key file (handles both CNG and CSP key storage)
Write-Host "`nLocating private key file..." -ForegroundColor Cyan
$keyFilePath = $null

try {
    # Use PrivateKey property for compatibility with PowerShell 5.1 and 7
    $rsa = $cert.PrivateKey
    
    if ($rsa -is [System.Security.Cryptography.RSACng]) {
        # CNG keys -> ProgramData\Microsoft\Crypto\Keys
        $uniqueName = $rsa.Key.UniqueName
        $keyFilePath = Join-Path $env:ProgramData "Microsoft\Crypto\Keys\$uniqueName"
    }
    elseif ($rsa -is [System.Security.Cryptography.RSACryptoServiceProvider]) {
        # CSP keys -> ProgramData\Microsoft\Crypto\RSA\MachineKeys
        $uniqueName = $rsa.CspKeyContainerInfo.UniqueKeyContainerName
        $keyFilePath = Join-Path $env:ProgramData "Microsoft\Crypto\RSA\MachineKeys\$uniqueName"
    }
    
    if (-not $keyFilePath -or -not (Test-Path $keyFilePath)) {
        throw "Could not determine private key file path."
    }
    
    Write-Host "Private key file located: $keyFilePath" -ForegroundColor Green
} catch {
    throw "Failed to locate private key file: $($_)"
}

# Grant gMSA account read access to private key
Write-Host "`nGranting Read access to '$gMSA' on private key file..." -ForegroundColor Cyan

try {
    $acl = Get-Acl -Path $keyFilePath
    $rule = New-Object System.Security.AccessControl.FileSystemAccessRule(
        $gMSA,
        [System.Security.AccessControl.FileSystemRights]::Read,
        [System.Security.AccessControl.InheritanceFlags]::None,
        [System.Security.AccessControl.PropagationFlags]::None,
        [System.Security.AccessControl.AccessControlType]::Allow)
    
    $acl.AddAccessRule($rule)
    Set-Acl -Path $keyFilePath -AclObject $acl
    Write-Host "ACL updated successfully!" -ForegroundColor Green
} catch {
    Write-Warning "Set-Acl failed: $_. Attempting icacls fallback..."
    $escapedAccount = $gMSA -replace '"','\"'
    $icaclsCmd = "icacls `"$keyFilePath`" /grant `"$escapedAccount`:R`" /C"
    Write-Host "Running: $icaclsCmd" -ForegroundColor Yellow
    cmd.exe /c $icaclsCmd
}

Write-Host "`nCertificate installation complete!" -ForegroundColor Green
Write-Host "Store location: LocalMachine\My (use certlm.msc to view)" -ForegroundColor Cyan
Write-Host "Next steps:" -ForegroundColor Cyan
Write-Host "  1. Configure Nodinite to use this certificate thumbprint: $($cert.Thumbprint)"
Write-Host "  2. Verify gMSA account can access the certificate"
Write-Host "  3. Test service startup with gMSA account"
```

### Usage - Self-Signed Certificate

1. Save the script as `New-GmsaCertificate.ps1`
2. Open PowerShell as Administrator (PowerShell 5.1+ or PowerShell 7+)
3. Run with parameters:

   ```powershell
   .\New-GmsaCertificate.ps1 -Subject "CN=NodiniteProdSvc" -gMSA "CONTOSO\NodiniteProdSvc$" -ValidityYears 3
   ```

4. Copy the certificate thumbprint for use in Nodinite configuration

### Key Improvements

* **Handles both CNG and CSP keys** - Modern certificates use CNG (Crypto Next Generation), older ones use CSP (Cryptographic Service Provider)
* **Automatic key location detection** - Searches correct paths for both storage types
* **Fallback to icacls** - If PowerShell ACL setting fails, falls back to icacls command
* **Administrator check** - Validates elevation before attempting changes
* **Exportable keys** - Allows certificate backup if needed

---

## Option 2: Import an Existing Certificate (PFX)

Use this script when you have a certificate from a Certificate Authority (CA) or an existing PFX file:

```powershell
# PowerShell script to import existing certificate for gMSA
# Compatible with PowerShell 5.1+ and PowerShell 7+
# Must be run with Administrator privileges

# Configuration
$certificatePath = "C:\Certificates\NodiniteCert.pfx"  # Path to your certificate file
$pfxPassword = Read-Host "Enter PFX password" -AsSecureString  # Prompt for password securely
$gmsaAccount = "CONTOSO\NodiniteProdSvc$"  # Your gMSA account with trailing $
$certStorePath = "Cert:\LocalMachine\My"

# Import certificate into LocalMachine store
Write-Host "Importing certificate from: $certificatePath" -ForegroundColor Cyan

try {
    $cert = Import-PfxCertificate `
        -FilePath $certificatePath `
        -CertStoreLocation $certStorePath `
        -Password $pfxPassword `
        -Exportable
    
    Write-Host "Certificate imported successfully!" -ForegroundColor Green
    Write-Host "  Thumbprint: $($cert.Thumbprint)" -ForegroundColor Yellow
    Write-Host "  Subject: $($cert.Subject)" -ForegroundColor Yellow
    Write-Host "  Issuer: $($cert.Issuer)" -ForegroundColor Yellow
    Write-Host "  Expires: $($cert.NotAfter)" -ForegroundColor Yellow
} catch {
    Write-Error "Failed to import certificate: $_"
    exit 1
}

# Grant gMSA account access to certificate private key
Write-Host "`nGranting gMSA account access to certificate private key..." -ForegroundColor Cyan

# Get the certificate's private key file path
try {
    # Use PrivateKey property for compatibility with PowerShell 5.1 and 7
    $rsa = $cert.PrivateKey
    $keyFilePath = $null
    
    if ($rsa -is [System.Security.Cryptography.RSACng]) {
        # CNG keys -> ProgramData\Microsoft\Crypto\Keys
        $uniqueName = $rsa.Key.UniqueName
        $keyFilePath = Join-Path $env:ProgramData "Microsoft\Crypto\Keys\$uniqueName"
    }
    elseif ($rsa -is [System.Security.Cryptography.RSACryptoServiceProvider]) {
        # CSP keys -> ProgramData\Microsoft\Crypto\RSA\MachineKeys
        $uniqueName = $rsa.CspKeyContainerInfo.UniqueKeyContainerName
        $keyFilePath = Join-Path $env:ProgramData "Microsoft\Crypto\RSA\MachineKeys\$uniqueName"
    }
    
    if ($keyFilePath -and (Test-Path $keyFilePath)) {
        # Grant Read permission to gMSA account
        $acl = Get-Acl -Path $keyFilePath
        $permission = $gmsaAccount, "Read", "Allow"
        $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
        $acl.AddAccessRule($accessRule)
        Set-Acl -Path $keyFilePath -AclObject $acl
        
        Write-Host "Successfully granted '$gmsaAccount' Read access to private key!" -ForegroundColor Green
    } else {
        Write-Warning "Could not locate private key file at: $keyFilePath"
        Write-Warning "You may need to grant permissions manually using certlm.msc"
    }
} catch {
    Write-Warning "Could not set private key permissions automatically: $_"
    Write-Warning "Grant permissions manually:"
    Write-Warning "  1. Run 'certlm.msc' (Local Machine certificates)"
    Write-Warning "  2. Navigate to Personal > Certificates"
    Write-Warning "  3. Right-click the certificate > All Tasks > Manage Private Keys"
    Write-Warning "  4. Add '$gmsaAccount' with Read permission"
}

Write-Host "`nCertificate installation complete!" -ForegroundColor Green
Write-Host "Next steps:" -ForegroundColor Cyan
Write-Host "  1. Configure Nodinite to use this certificate thumbprint: $($cert.Thumbprint)"
Write-Host "  2. Verify gMSA account can access the certificate"
Write-Host "  3. Test service startup with gMSA account"
```

### Usage - PFX Import

1. Place your PFX certificate file on the server
2. Edit the `$certificatePath` and `$gmsaAccount` variables
3. Open PowerShell as Administrator (PowerShell 5.1+ or PowerShell 7+)
4. Run the script and enter the PFX password when prompted
5. Copy the certificate thumbprint for use in Nodinite configuration

---

## Option 3: Import Certificate from PEM Files (Separate Cert + Key)

Use this script when you have separate certificate and private key files (common with OpenSSL or Linux-based PKI):

```powershell
# PowerShell script to import PEM certificate and key for gMSA
# Compatible with PowerShell 5.1+ and PowerShell 7+
# Must be run with Administrator privileges

# Configuration
$certPemPath = "C:\Certificates\certificate.pem"  # Path to certificate PEM file
$keyPemPath = "C:\Certificates\private-key.pem"   # Path to private key PEM file
$gmsaAccount = "CONTOSO\NodiniteProdSvc$"          # Your gMSA account with trailing $
$certStorePath = "Cert:\LocalMachine\My"

Write-Host "Converting PEM files to PFX format..." -ForegroundColor Cyan

# Create temporary PFX with random password
$tempPfxPath = "$env:TEMP\temp_cert_$(Get-Random).pfx"
$tempPassword = -join ((65..90) + (97..122) + (48..57)|Get-Random -Count 20|ForEach-Object {[char]$_})
$securePassword = ConvertTo-SecureString -String $tempPassword -AsPlainText -Force

try {
    # Convert PEM to PFX using OpenSSL (must be installed)
    $opensslPath = "openssl"  # Assumes OpenSSL is in PATH
    
    # Test if OpenSSL is available
    try {
        $null = & $opensslPath version 2>&1
    } catch {
        Write-Error "OpenSSL not found. Install OpenSSL or use Option 2 with a PFX file."
        Write-Error "Download OpenSSL from: https://slproweb.com/products/Win32OpenSSL.html"
        exit 1
    }
    
    # Convert PEM to PFX
    & $opensslPath pkcs12 -export `
        -in $certPemPath `
        -inkey $keyPemPath `
        -out $tempPfxPath `
        -password "pass:$tempPassword" 2>&1 | Out-Null
    
    if (-not (Test-Path $tempPfxPath)) {
        throw "Failed to create temporary PFX file"
    }
    
    Write-Host "PEM conversion successful!" -ForegroundColor Green
    
    # Import the temporary PFX
    Write-Host "Importing certificate into LocalMachine store..." -ForegroundColor Cyan
    
    $cert = Import-PfxCertificate `
        -FilePath $tempPfxPath `
        -CertStoreLocation $certStorePath `
        -Password $securePassword `
        -Exportable
    
    Write-Host "Certificate imported successfully!" -ForegroundColor Green
    Write-Host "  Thumbprint: $($cert.Thumbprint)" -ForegroundColor Yellow
    Write-Host "  Subject: $($cert.Subject)" -ForegroundColor Yellow
    Write-Host "  Issuer: $($cert.Issuer)" -ForegroundColor Yellow
    Write-Host "  Expires: $($cert.NotAfter)" -ForegroundColor Yellow
    
    # Grant gMSA account access to certificate private key
    Write-Host "`nGranting gMSA account access to certificate private key..." -ForegroundColor Cyan
    
    $rsaCert = [System.Security.Cryptography.X509Certificates.RSACertificateExtensions]::GetRSAPrivateKey($cert)
    if ($rsaCert -is [System.Security.Cryptography.RSACng]) {
        # CNG keys -> ProgramData\Microsoft\Crypto\Keys
        $privateKeyPath = Join-Path $env:ProgramData "Microsoft\Crypto\Keys\$($rsaCert.Key.UniqueName)"
    } else {
        # CSP keys -> ProgramData\Microsoft\Crypto\RSA\MachineKeys
        $privateKeyPath = Join-Path $env:ProgramData "Microsoft\Crypto\RSA\MachineKeys\$($rsaCert.CspKeyContainerInfo.UniqueKeyContainerName)"
    }
    
    if (Test-Path $privateKeyPath) {
        $acl = Get-Acl -Path $privateKeyPath
        $permission = $gmsaAccount, "Read", "Allow"
        $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
        $acl.AddAccessRule($accessRule)
        Set-Acl -Path $privateKeyPath -AclObject $acl
        
        Write-Host "Successfully granted '$gmsaAccount' Read access to private key!" -ForegroundColor Green
    } else {
        Write-Warning "Could not locate private key file at: $privateKeyPath"
    }
    
    Write-Host "`nCertificate installation complete!" -ForegroundColor Green
    Write-Host "Next steps:" -ForegroundColor Cyan
    Write-Host "  1. Configure Nodinite to use this certificate thumbprint: $($cert.Thumbprint)"
    Write-Host "  2. Verify gMSA account can access the certificate"
    Write-Host "  3. Test service startup with gMSA account"
    
} catch {
    Write-Error "Failed to import certificate: $_"
    exit 1
} finally {
    # Clean up temporary PFX file
    if (Test-Path $tempPfxPath) {
        Remove-Item $tempPfxPath -Force
        Write-Host "`nTemporary files cleaned up." -ForegroundColor Gray
    }
}
```

### Usage - PEM Import

1. Install [OpenSSL for Windows](https://slproweb.com/products/Win32OpenSSL.html)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup> if it isn't already installed
2. Place your PEM certificate and key files on the server
3. Edit the `$certPemPath`, `$keyPemPath`, and `$gmsaAccount` variables
4. Open PowerShell as Administrator (PowerShell 5.1+ or PowerShell 7+)
5. Run the script
6. Copy the certificate thumbprint for use in Nodinite configuration

---

## Verifying Certificate Installation

After running any of the above scripts, verify the certificate is properly installed:

```powershell
# List all certificates in LocalMachine\My store
Get-ChildItem -Path Cert:\LocalMachine\My|Format-Table Subject, Thumbprint, NotAfter

# Verify specific certificate by thumbprint
$thumbprint = "YOUR_CERTIFICATE_THUMBPRINT_HERE"
$cert = Get-ChildItem -Path Cert:\LocalMachine\My|Where-Object {$_.Thumbprint -eq $thumbprint}

if ($cert) {
    Write-Host "Certificate found!" -ForegroundColor Green
    Write-Host "  Subject: $($cert.Subject)"
    Write-Host "  Issuer: $($cert.Issuer)"
    Write-Host "  Expires: $($cert.NotAfter)"
    Write-Host "  Has Private Key: $($cert.HasPrivateKey)"
} else {
    Write-Warning "Certificate not found in LocalMachine\My store"
}
```

---

## Certificate Management Best Practices

* **Expiration Monitoring:** Set up alerts to notify you 30-60 days before certificate expiration
* **Renewal Process:** Document your certificate renewal process and test it in non-production environments
* **Backup Certificates:** Export certificates (with private keys) and store securely for disaster recovery
* **Naming Convention:** Use consistent certificate subject names that match your gMSA account names (e.g., CN=NodiniteProdSvc)
* **Validity Period:** For production, use 1-3 year validity. For testing, shorter periods are acceptable

<aside aria-label="Tip" class="nodinite-note nodinite-note--tip">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-lightbulb"></i> Tip</p>
<div class="nodinite-note__content"><p>Set calendar reminders 60 days before expiration. Consider using the <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> <a href="https://docs.nodinite.com/logging-and-monitoring/windows-server/overview/">Windows Server Monitoring Agent</a> to <a href="https://docs.nodinite.com/logging-and-monitoring/windows-server/features/certificates/overview/">monitor certificate expiration dates</a> automatically.</p></div>
</aside>

<aside aria-label="Warning" class="nodinite-note nodinite-note--warning">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-triangle-exclamation"></i> Warning</p>
<div class="nodinite-note__content"><ul>
<li>Always use secure passwords when creating/importing PFX files</li>
<li>Delete temporary certificate files after import</li>
<li>Restrict access to certificate export files (store in secured locations)</li>
<li>Use proper ACLs - only grant necessary accounts Read access to private keys</li>
<li>Consider using Hardware Security Modules (HSM) for production certificates</li>
</ul></div>
</aside>

---

## Troubleshooting Certificate Issues

### "Private key not found" or "Cannot locate private key file"

Script is looking in the wrong location for the private key.

* **Modern certificates (CNG)**: Keys stored in `%ProgramData%\Microsoft\Crypto\Keys\`
* **Legacy certificates (CSP)**: Keys stored in `%ProgramData%\Microsoft\Crypto\RSA\MachineKeys\`

The scripts on this page automatically detect both locations. If using a different script or manual process, check both paths.

#### Manual Verification

```powershell
# List all keys in CNG location
Get-ChildItem "$env:ProgramData\Microsoft\Crypto\Keys\"

# List all keys in CSP location
Get-ChildItem "$env:ProgramData\Microsoft\Crypto\RSA\MachineKeys\"
```

### "Set-Acl: Access is denied"

Insufficient permissions or protected key file.

The scripts automatically fall back to `icacls` command. If both fail, you may need to:

1. Verify you're running as Administrator
2. Check if antivirus/security software is blocking ACL changes
3. Manually set permissions using `certlm.msc`:
   * Run `certlm.msc` (Local Machine certificates)
   * Navigate to **Personal > Certificates**
   * Right-click certificate > **All Tasks > Manage Private Keys**
   * Add your gMSA account (e.g., `CONTOSO\NodiniteProdSvc$`) with **Read** permission

### Certificate created but service still fails with "Cannot find certificate"

Certificate in wrong store or gMSA lacks permission.

1. Verify certificate is in LocalMachine\My store:

   ```powershell
   Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.Subject -like "*NodiniteProdSvc*"}  
   ```

2. Verify gMSA has Read permission on private key:

   ```powershell
   # Find the private key file (example for CNG)
   $cert = Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.Thumbprint -eq "YOUR_THUMBPRINT"}  
   $rsa = $cert.GetRSAPrivateKey()
   $keyPath = Join-Path $env:ProgramData "Microsoft\Crypto\Keys\$($rsa.Key.UniqueName)"
   
   # Check ACL
   Get-Acl $keyPath | Select-Object -ExpandProperty Access | Where-Object {$_.IdentityReference -like "*NodiniteProdSvc*"}  
   ```

3. Verify certificate thumbprint matches configuration in Nodinite

### "OpenSSL not found" (Option 3 - PEM files)

OpenSSL not installed or not in PATH.

1. Download and install [OpenSSL for Windows](https://slproweb.com/products/Win32OpenSSL.html)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup>
2. Add OpenSSL bin folder to PATH, or specify full path in script:

   ```powershell
   $opensslPath = "C:\Program Files\OpenSSL-Win64\bin\openssl.exe"
   ```

3. Alternative: Use Option 2 and convert PEM to PFX manually first

### Certificate expires - how to renew without downtime?

1. Create/import new certificate with new thumbprint
2. Grant gMSA account Read permission on new certificate's private key
3. Update Nodinite configuration with new thumbprint
4. Restart Nodinite services (they'll pick up new certificate)
5. After verification, delete old certificate. Allow at least 24 hours overlap to avoid downtime. We recommend a week overlap in production.

<aside aria-label="Tip" class="nodinite-note nodinite-note--tip">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-lightbulb"></i> Tip</p>
<div class="nodinite-note__content"><p>Set up monitoring to alert 30-60 days before certificate expiration. This gives time to plan renewals during maintenance windows.</p></div>
</aside>

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* <i class="fal fa-shield-check" aria-hidden="true"></i> [Configure Group Managed Service Accounts (gMSA)][gMSA] - Return to the main gMSA configuration guide  
* <i class="fal fa-right-left" aria-hidden="true"></i> [Migrate Traditional Account to gMSA][] - Move an existing installation to a gMSA  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-key" aria-hidden="true"></i> [Secret Management][] - Certificate-based encryption in <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> v7  
* <i class="fal fa-user-plus" aria-hidden="true"></i> [How to set Logon as a Service right][LogonAsAService] - Service account permissions  
* <i class="fal fa-triangle-exclamation" aria-hidden="true"></i> [FAQ - gMSA Troubleshooting][] - Certificate access and decryption failures  
* <i class="fal fa-wrench" aria-hidden="true"></i> [Troubleshooting][] - General installation and configuration help  
* <i class="fal fa-key" aria-hidden="true"></i> [Step 2: Auth – Secret Management][Step02 Secret Management]  

[Core Services]:https://docs.nodinite.com/core-services/overview/
[FAQ - gMSA Troubleshooting]:https://docs.nodinite.com/install-and-update/troubleshooting/windows/gmsa/faq-gmsa-troubleshooting/
[gMSA]:https://docs.nodinite.com/install-and-update/troubleshooting/windows/gmsa-accounts/
[Install Nodinite v7 - TLS]:https://docs.nodinite.com/install-and-update/getting-started/version-7/install-nodinite-v7-steps/04-servers/#core-host-tls
[LogonAsAService]:https://docs.nodinite.com/install-and-update/troubleshooting/windows/logon-as-a-service-right/
[Migrate Traditional Account to gMSA]:https://docs.nodinite.com/install-and-update/troubleshooting/windows/gmsa/migration-from-traditional-account/
[Secret Management]:https://docs.nodinite.com/install-and-update/troubleshooting/secret-managment/
[Step02 Secret Management]:https://docs.nodinite.com/install-and-update/getting-started/version-7/install-nodinite-v7-steps/02-auth/#secret-management
[Troubleshooting]:https://docs.nodinite.com/install-and-update/troubleshooting/overview/
[Windows Certificates]:https://docs.nodinite.com/logging-and-monitoring/windows-server/features/certificates/overview/
[Windows Server Monitoring Agent]:https://docs.nodinite.com/logging-and-monitoring/windows-server/overview/