How can I change a login of a user in samba4 based domain?
I've tried reading the samba-tool man page, but it does not seem to show anything that i could use.
How can I change a login of a user in samba4 based domain?
I've tried reading the samba-tool man page, but it does not seem to show anything that i could use.
Assuming we use Ubuntu and Samba 4 is configured as a DC (Active Directory Domain Controller) and we want to change the user with name
Old User
and loginolduser
. To just rename a users login name, we can usesamba-tool
:This will open an editor showing the content of the LDAP entry. Change the attributes
sAMAccountName
anduserPrincipalName
, save and exit. You may also want to rename any existing home directory of the user.We can also edit the LDAP entry directly without using the
samba-tool
but with theldb-tools
.Install
ldb-tools
:Now we can use the
ldb-tools
(ldbadd
,ldbdel
,ldbedit
,ldbmodify
,ldbrename
,ldbsearch
) to search or modify the LDAP database directly.Locate the Samba LDAP database:
If you installed an Ubuntu packaged version of
samba
, this file should be found at/var/lib/samba/private/sam.ldb
.Let's first have a look at that user in the LDAP database:
Search the database:
We use
ldbsearch
for that with the following syntax:With the
<ldap-filter>
we can specify an expression to filter the entries returned by the search. We can for example usesAMAccountName=olduser
to filter based on the login name attribute orCN=Old User
to filter based on the CN (Common Name) attribute:Change the login name attributes
Create a text file (
rename-login.ldif
) with the following contents:This will modify the attributes
sAMAccountName
anduserPrincipalName
:Rename the LDAP entry by renaming the RDN (Relative Distinguished Name)
It looks like renaming an LDAP entry is not possible using the
samba-tool
and we have to useldb-tools
:This will also change the attributes
cn
andname
, but not some other attributes, still containing the old user name as shown by the next search:Modify the remaining attributes
To also change some other attributes, like for example
givenName
,displayName
ormail
, we can use:and edit the user interactively or use another
ldbmodify
as follows:Create a text file (
rename-other-attrs.ldif
) with the following contents:Modify the LDAP entry::