samba4 ドメインのユーザーの名前を変更するにはどうすればいいですか?

samba4 ドメインのユーザーの名前を変更するにはどうすればいいですか?

samba4 ベースのドメインでユーザーのログインを変更するにはどうすればよいですか?

samba-tool のマニュアルページを読んでみましたが、使用できるものは何も示されていないようです。

答え1

Ubuntu を使用しており、Samba 4 が DC (Active Directory ドメイン コントローラー) として構成されており、 nameOld Userと login を使用してユーザーを変更するとしますolduser。ユーザーのログイン名を変更するには、次を使用しますsamba-tool

test-smb:~# samba-tool user edit olduser

これにより、LDAP エントリの内容を表示するエディターが開きます。属性とを変更しsAMAccountNameuserPrincipalName保存して終了します。ユーザーの既存のホーム ディレクトリの名前を変更することもできます。

samba-toolを使用せずに、を使ってLDAP エントリを直接編集することもできますldb-tools

インストールldb-tools

apt install ldb-tools

これで、ldb-tools( ldbaddldbdelldbeditldbmodify、 ) を使用してldbrenameldbsearchLDAP データベースを直接検索または変更できるようになりました。

Samba LDAP データベースを見つけます。

の Ubuntu パッケージ バージョンをインストールした場合samba、このファイルは にあります/var/lib/samba/private/sam.ldb

まず、LDAP データベース内のそのユーザーを見てみましょう。

データベースを検索:

ldbsearchそのために次の構文を使用します。

ldbsearch -H <database-file> <ldap-filter>

を使用すると<ldap-filter>、検索によって返されるエントリをフィルタリングするための式を指定できます。たとえば、sAMAccountName=olduserログイン名属性に基づいてフィルタリングしたり、CN=Old UserCN (共通名) 属性に基づいてフィルタリングしたりすることができます。

test-smb:~# ldbsearch -H /var/lib/samba/private/sam.ldb 'CN=Old User'
# record 1
dn: CN=Old User,CN=Users,DC=test-smb,DC=example,DC=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
cn: Old User
sn: User
givenName: Old
instanceType: 4
whenCreated: 20180904091809.0Z
whenChanged: 20180904091809.0Z
displayName: Old User
uSNCreated: 3841
name: Old User
objectGUID: 038979ea-107d-4c97-85bf-76d1f2326608
badPwdCount: 0
codePage: 0
countryCode: 0
badPasswordTime: 0
lastLogoff: 0
lastLogon: 0
primaryGroupID: 513
objectSid: S-1-5-21-3075026989-1808589244-366107480-1105
accountExpires: 9223372036854775807
logonCount: 0
sAMAccountName: olduser
sAMAccountType: 805306368
userPrincipalName: [email protected]
objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=test-smb,DC=phys,DC=et
 hz,DC=ch
mail: [email protected]
loginShell: /bin/bash
pwdLastSet: 131805262894707270
userAccountControl: 512
uSNChanged: 3844
distinguishedName: CN=Old User,CN=Users,DC=test-smb,DC=example,DC=com

...

ログイン名属性を変更する

rename-login.ldif次の内容のテキストファイル ( ) を作成します。

dn: CN=Old User,CN=Users,DC=test-smb,DC=phys,DC=ethz,DC=ch
changetype: modify
replace: sAMAccountName
sAMAccountName: newuser
-
replace: userPrincipalName
userPrincipalName: [email protected]

これにより、属性が変更されますsAMAccountNameuserPrincipalName

test-smb:~# ldbmodify -H /var/lib/samba/private/sam.ldb rename-login.ldif
Modified 1 records successfully

RDN (相対識別名) の名前を変更して、LDAP エントリの名前を変更します。

LDAP エントリの名前を変更するには を使用することはできないようです。samba-toolを使用する必要がありますldb-tools

test-smb:~# ldbrename -H /var/lib/samba/private/sam.ldb 'CN=Old User,CN=Users,DC=test-smb,DC=example,DC=com' 'CN=New User,CN=Users,DC=test-smb,DC=example,DC=com'
Renamed 1 record

これにより、属性とも変更されますcnname、他の一部の属性は変更されず、次の検索に示すように、古いユーザー名がまだ含まれています。

test-smb:~# ldbsearch -H /var/lib/samba/private/sam.ldb 'CN=New User'
# record 1
dn: CN=New User,CN=Users,DC=test-smb,DC=example,DC=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
sn: User
givenName: Old
instanceType: 4
whenCreated: 20180904091809.0Z
displayName: Old User
uSNCreated: 3841
objectGUID: 038979ea-107d-4c97-85bf-76d1f2326608
badPwdCount: 0
codePage: 0
countryCode: 0
badPasswordTime: 0
lastLogoff: 0
primaryGroupID: 513
objectSid: S-1-5-21-3075026989-1808589244-366107480-1105
accountExpires: 9223372036854775807
sAMAccountType: 805306368
objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=test-smb,DC=phys,DC=et
 hz,DC=ch
mail: [email protected]
loginShell: /bin/bash
pwdLastSet: 131805262894707270
userAccountControl: 512
lastLogonTimestamp: 131805264616461980
sAMAccountName: newuser
userPrincipalName: [email protected]
lastLogon: 131805271152497360
logonCount: 12
cn: New User
name: New User
whenChanged: 20180904100228.0Z
uSNChanged: 3847
distinguishedName: CN=New User,CN=Users,DC=test-smb,DC=example,DC=com

残りの属性を変更する

たとえばgivenNamedisplayNameや などの他の属性も変更するにはmail、次を使用します。

samba-tool user edit newuser

ユーザーを対話的に編集するか、ldbmodify次のように別のユーザーを使用します。

rename-other-attrs.ldif次の内容のテキストファイル ( ) を作成します。

dn: CN=New User,CN=Users,DC=test-smb,DC=phys,DC=ethz,DC=ch
changetype: modify
replace: givenName
givenName: New
-
replace: displayName
displayName: New User
-
replace: mail
mail: [email protected]

LDAP エントリを変更します::

test-smb:~# ldbmodify -H /var/lib/samba/private/sam.ldb rename-other-attrs.ldif
Modified 1 records successfully

答え2

明白な方法を試すこともできます:

/ # samba-tool user rename  --help
Usage: samba-tool user rename <username> [options]

Rename a user and related attributes.

This command allows to set the user's name related attributes. The user's
CN will be renamed automatically.
The user's new CN will be made up by combining the given-name, initials
and surname. A dot ('.') will be appended to the initials automatically
if required.
Use the --force-new-cn option to specify the new CN manually and the
--reset-cn option to reset this change.

Use an empty attribute value to remove the specified attribute.

The username specified on the command is the sAMAccountName.

The command may be run locally from the root userid or another authorized
userid.

The -H or --URL= option can be used to execute the command against a remote
server.

Example1:
samba-tool user rename johndoe --surname='Bloggs'

Example1 shows how to change the surname of a user 'johndoe' to 'Bloggs' on
the local server. The user's CN will be renamed automatically, based on
the given name, initials and surname.

Example2:
samba-tool user rename johndoe --force-new-cn='John Bloggs (Sales)' \
    --surname=Bloggs -H ldap://samba.samdom.example.com -U administrator

Example2 shows how to rename the CN of a user 'johndoe' to 'John Bloggs
(Sales)'.
Additionally the surname ('sn' attribute) is set to 'Bloggs'.
The -H parameter is used to specify the remote target server.

Active Directory では「ログイン」の定義が多数あるため、これを投稿しています (つまり、userPrincipalName を使用できるほか、他のオプションもあります。たとえば、私が取り組んでいるアプリでは、ユーザーは CN だけでログインできます)。

関連情報