如何在基于samba4的域中更改用户的登录?
我试过阅读samba工具手册页,但它似乎没有显示我可以使用的任何东西。
发布于 2018-09-03 11:59:31
假设我们使用Ubuntu和Samba 4,则将其配置为DC (),并希望更改名为Old User和登录olduser的用户。要重命名用户登录名,我们可以使用samba-tool:
test-smb:~# samba-tool user edit olduser这将打开一个编辑器,显示LDAP条目的内容。更改属性sAMAccountName和userPrincipalName,保存和退出。您还可能希望重命名用户的任何现有主目录。
我们还可以直接编辑LDAP条目,而无需使用samba-tool,而是使用ldb-tools。
ldb-tools:apt install ldb-tools现在我们可以使用ldb-tools (ldbadd、ldbdel、ldbedit、ldbmodify、ldbrename、ldbsearch)直接搜索或修改LDAP数据库。
如果您安装了Ubuntu打包版本的samba,这个文件应该可以在/var/lib/samba/private/sam.ldb上找到。
让我们首先看看LDAP数据库中的用户:
为此,我们使用ldbsearch,语法如下:
ldbsearch -H <database-file> <ldap-filter>使用<ldap-filter>,我们可以指定一个表达式来过滤搜索返回的条目。例如,我们可以使用sAMAccountName=olduser根据登录名属性进行筛选,或者使用CN=Old User根据CN (公共名称)属性进行筛选:
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: olduser@test-smb.example.com
objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=test-smb,DC=phys,DC=et
hz,DC=ch
mail: olduser@test-smb.example.com
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: newuser@test-smb.phys.ethz.ch这将修改属性sAMAccountName和userPrincipalName:
test-smb:~# ldbmodify -H /var/lib/samba/private/sam.ldb rename-login.ldif
Modified 1 records successfully来重命名LDAP条目
看起来,使用samba-tool重命名LDAP条目是不可能的,我们必须使用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这还将更改属性cn和name,但不会更改其他一些属性,这些属性仍然包含旧用户名,如下一次搜索所示:
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: olduser@test-smb.example.com
loginShell: /bin/bash
pwdLastSet: 131805262894707270
userAccountControl: 512
lastLogonTimestamp: 131805264616461980
sAMAccountName: newuser
userPrincipalName: newuser@test-smb.example.com
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要更改其他一些属性,例如givenName、displayName或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: newuser@test-smb.example.com修改LDAP条目::
test-smb:~# ldbmodify -H /var/lib/samba/private/sam.ldb rename-other-attrs.ldif
Modified 1 records successfully发布于 2023-05-31 14:43:35
人们也可以尝试显而易见的:
/ # 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登录)
https://serverfault.com/questions/928830
复制相似问题