<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>activedirectory &amp;mdash; Kevin Sandy</title>
    <link>https://kevinsandy.com/tag:activedirectory</link>
    <description>Thoughts, musings, ramblings, and rants</description>
    <pubDate>Fri, 17 Apr 2026 07:50:53 +0000</pubDate>
    <image>
      <url>https://i.snap.as/IC0yYUyI.png</url>
      <title>activedirectory &amp;mdash; Kevin Sandy</title>
      <link>https://kevinsandy.com/tag:activedirectory</link>
    </image>
    <item>
      <title>Synology DiskStation User Mapping</title>
      <link>https://kevinsandy.com/synology-diskstation-user-mapping?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[I have a Synology DiskStation providing file services to my home and lab networks. It works great as-is for SMB access, but NFS access was problematic because the automatic UID / GID generation didn&#39;t match the IDs used by my Linux systems. Since I already store Unix attributes in Active Directory, I needed the DiskStation to respect those.&#xA;&#xA;!--more--&#xA;&#xA;The first step to acheive this is to update the Samba configuration (/etc/samba/smb.conf) on your DiskStation. Adding the configuration below will get Samba to use the Active Directory attributes. I use 100000-199999 for my user and group IDs. If you use different values you may need to adjust it a bit. If you don&#39;t yet have Unix attributes assigned to your Active Directory users, check out Assigning Unix Attributes to Active Directory Objects for how I&#39;ve gone about that.&#xA;&#xA;[global]&#xA;    idmap config  : backend=tdb&#xA;    idmap config  : range=3000-7999&#xA;    idmap config DIGITALLOTUS : backend=ad&#xA;    idmap config DIGITALLOTUS : range=100000-199999&#xA;    idmap config DIGITALLOTUS : schemamode=rfc2307&#xA;    idmap config DIGITALLOTUS : unixnssinfo=yes&#xA;    idmap config DIGITALLOTUS : unixprimary_group=yes&#xA;&#xA;Once that is in place, restart your DiskStation. After it&#39;s up, you can check the user ID by running id user@corp.example.com and see that... it&#39;s still showing the automatically generated ID? That&#39;s actually expected at this point because of some of the DiskStation internals. If you run wbinfo -i &#34;user@corp.example.com&#34;, which will query Samba directly, you should see the right information.&#xA;&#xA;So, how do we now get the DiskStation to recognize the updated values? We have to clear its cached mappings. You can do that by running the command below.&#xA;&#xA;find /volume1/@accountdb \( -type f -o -type l \) -delete&#xA;&#xA;After running that command, you should be able to rerun id user@corp.example.com and see the right attributes. I did all this prior to setting up my shares and permissions. If you already have shares and permissions setup, you&#39;ll likely need to reapply your permissions to get them working with the new ID values.&#xA;&#xA;#activedirectory #diskstation]]&gt;</description>
      <content:encoded><![CDATA[<p>I have a Synology DiskStation providing file services to my home and lab networks. It works great as-is for SMB access, but NFS access was problematic because the automatic UID / GID generation didn&#39;t match the IDs used by my Linux systems. Since I already store Unix attributes in Active Directory, I needed the DiskStation to respect those.</p>



<p>The first step to acheive this is to update the Samba configuration (<code>/etc/samba/smb.conf</code>) on your DiskStation. Adding the configuration below will get Samba to use the Active Directory attributes. I use 100000-199999 for my user and group IDs. If you use different values you may need to adjust it a bit. If you don&#39;t yet have Unix attributes assigned to your Active Directory users, check out <a href="./assigning-unix-attributes-to-active-directory-object">Assigning Unix Attributes to Active Directory Objects</a> for how I&#39;ve gone about that.</p>

<pre><code class="language-ini">[global]
    idmap config * : backend=tdb
    idmap config * : range=3000-7999
    idmap config DIGITALLOTUS : backend=ad
    idmap config DIGITALLOTUS : range=100000-199999
    idmap config DIGITALLOTUS : schema_mode=rfc2307
    idmap config DIGITALLOTUS : unix_nss_info=yes
    idmap config DIGITALLOTUS : unix_primary_group=yes
</code></pre>

<p>Once that is in place, restart your DiskStation. After it&#39;s up, you can check the user ID by running <code>id user@corp.example.com</code> and see that... it&#39;s still showing the automatically generated ID? That&#39;s actually expected at this point because of some of the DiskStation internals. If you run <code>wbinfo -i &#34;user@corp.example.com&#34;</code>, which will query Samba directly, you should see the right information.</p>

<p>So, how do we now get the DiskStation to recognize the updated values? We have to clear its cached mappings. You can do that by running the command below.</p>

<pre><code class="language-bash">find /volume1/@accountdb \( -type f -o -type l \) -delete
</code></pre>

<p>After running that command, you should be able to rerun <code>id user@corp.example.com</code> and see the right attributes. I did all this prior to setting up my shares and permissions. If you already have shares and permissions setup, you&#39;ll likely need to reapply your permissions to get them working with the new ID values.</p>

<p><a href="https://kevinsandy.com/tag:activedirectory" class="hashtag"><span>#</span><span class="p-category">activedirectory</span></a> <a href="https://kevinsandy.com/tag:diskstation" class="hashtag"><span>#</span><span class="p-category">diskstation</span></a></p>
]]></content:encoded>
      <guid>https://kevinsandy.com/synology-diskstation-user-mapping</guid>
      <pubDate>Thu, 15 Dec 2022 12:55:32 +0000</pubDate>
    </item>
    <item>
      <title>Assigning Unix Attributes to Active Directory Objects</title>
      <link>https://kevinsandy.com/assigning-unix-attributes-to-active-directory-object?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[I run Active Directory to manage my users and groups. Most of my servers run Linux, and I also run a Synology DiskStation that serves files via NFS and CIFS. To keep file permissions and ownership consistent, I assign static UID and GID values to my Active Directory users and groups. Rather than manually assigning UID and GID values, I created a PowerShell script to do it for me.&#xA;&#xA;!--more--&#xA;&#xA;$objectBase = &#34;ou=Digital Lotus,dc=corp,dc=digitallotus,dc=com&#34;&#xA;$idRangeBase = 100000&#xA;$primaryGid = 101110&#xA;$loginShell = &#34;/bin/bash&#34;&#xA;$homeDirectoryBase = &#34;/users&#34;&#xA;&#xA;Get-ADObject `&#xA;        -LDAPFilter &#34;(&amp;(|(objectClass=user)(objectClass=group))(!objectClass=computer))&#34; `&#xA;        -SearchBase &#34;$objectBase&#34; `&#xA;        -Properties objectClass,objectSid,uidNumber,gidNumber,sAMAccountName,loginShell,unixHomeDirectory,primaryGroupID | ForEach {&#xA;        &#xA;    $sAMAccountName = $.sAMAccountName&#xA;    $objectRid = ($.objectSid -split &#34;-&#34;)[-1]&#xA;    $idNumber = $idRangeBase + $objectRid&#xA;&#xA;    if ( $.objectClass -eq &#34;user&#34; ) {&#xA;        if ( -not $.uidNumber ) {&#xA;            Write-Host &#34;Adding uidNumber $idNumber to $sAMAccountName&#34;&#xA;            $ | Set-ADObject -Add @{uidNumber=$idNumber}&#xA;        }&#xA;        if ( -not $.gidNumber ) {&#xA;            Write-Host &#34;Adding gidNumber $gidNumber to $sAMAccountName&#34;&#xA;            $ | Set-ADObject -Add @{gidNumber=$primaryGid }&#xA;        }&#xA;        if ( -not $.loginShell ) {&#xA;            Write-Host &#34;Adding loginShell $loginShell to $sAMAccountName&#34;&#xA;            $ | Set-ADObject -Add @{loginShell=$loginShell}&#xA;        }&#xA;        if ( -not $.unixHomeDirectory ) {&#xA;            $homeDirectory = &#34;$homeDirectoryBase/$sAMAccountName&#34;&#xA;            Write-Host &#34;Adding unixHomeDirectory $homeDirectory to $sAMAccountName&#34;&#xA;            $ | Set-ADObject -Add @{unixHomeDirectory=$homeDirectory}&#xA;        }&#xA;    }&#xA;&#xA;    if ( $.objectClass -eq &#34;group&#34; -and -not $.gidNumber ) {&#xA;        Write-Host &#34;Adding gidNumber $idNumber to $sAMAccountName&#34;&#xA;        $ | Set-ADObject -Add @{gidNumber=$idNumber}&#xA;    }&#xA;&#xA;}&#xA;&#xA;The objectBase variable is the base of the search for users and groups, and idRangeBase is the starting value for the IDs. The Active Directory object&#39;s relative ID is added to idRangeBase to create the actual UID or GID number.&#xA;&#xA;#activedirectory #powershell]]&gt;</description>
      <content:encoded><![CDATA[<p>I run Active Directory to manage my users and groups. Most of my servers run Linux, and I also run a Synology DiskStation that serves files via NFS and CIFS. To keep file permissions and ownership consistent, I assign static UID and GID values to my Active Directory users and groups. Rather than manually assigning UID and GID values, I created a PowerShell script to do it for me.</p>



<pre><code class="language-powershell">$objectBase = &#34;ou=Digital Lotus,dc=corp,dc=digitallotus,dc=com&#34;
$idRangeBase = 100000
$primaryGid = 101110
$loginShell = &#34;/bin/bash&#34;
$homeDirectoryBase = &#34;/users&#34;

Get-ADObject `
        -LDAPFilter &#34;(&amp;(|(objectClass=user)(objectClass=group))(!objectClass=computer))&#34; `
        -SearchBase &#34;$objectBase&#34; `
        -Properties objectClass,objectSid,uidNumber,gidNumber,sAMAccountName,loginShell,unixHomeDirectory,primaryGroupID | ForEach {
        
    $sAMAccountName = $_.sAMAccountName
    $objectRid = ($_.objectSid -split &#34;-&#34;)[-1]
    $idNumber = $idRangeBase + $objectRid

    if ( $_.objectClass -eq &#34;user&#34; ) {
        if ( -not $_.uidNumber ) {
            Write-Host &#34;Adding uidNumber $idNumber to $sAMAccountName&#34;
            $_ | Set-ADObject -Add @{uidNumber=$idNumber}
        }
        if ( -not $_.gidNumber ) {
            Write-Host &#34;Adding gidNumber $gidNumber to $sAMAccountName&#34;
            $_ | Set-ADObject -Add @{gidNumber=$primaryGid }
        }
        if ( -not $_.loginShell ) {
            Write-Host &#34;Adding loginShell $loginShell to $sAMAccountName&#34;
            $_ | Set-ADObject -Add @{loginShell=$loginShell}
        }
        if ( -not $_.unixHomeDirectory ) {
            $homeDirectory = &#34;$homeDirectoryBase/$sAMAccountName&#34;
            Write-Host &#34;Adding unixHomeDirectory $homeDirectory to $sAMAccountName&#34;
            $_ | Set-ADObject -Add @{unixHomeDirectory=$homeDirectory}
        }
    }

    if ( $_.objectClass -eq &#34;group&#34; -and -not $_.gidNumber ) {
        Write-Host &#34;Adding gidNumber $idNumber to $sAMAccountName&#34;
        $_ | Set-ADObject -Add @{gidNumber=$idNumber}
    }

}
</code></pre>

<p>The <code>objectBase</code> variable is the base of the search for users and groups, and <code>idRangeBase</code> is the starting value for the IDs. The Active Directory object&#39;s relative ID is added to <code>idRangeBase</code> to create the actual UID or GID number.</p>

<p><a href="https://kevinsandy.com/tag:activedirectory" class="hashtag"><span>#</span><span class="p-category">activedirectory</span></a> <a href="https://kevinsandy.com/tag:powershell" class="hashtag"><span>#</span><span class="p-category">powershell</span></a></p>
]]></content:encoded>
      <guid>https://kevinsandy.com/assigning-unix-attributes-to-active-directory-object</guid>
      <pubDate>Sun, 27 Nov 2022 15:29:05 +0000</pubDate>
    </item>
  </channel>
</rss>