AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 56830
Accepted
Clinton Blackmore
Clinton Blackmore
Asked: 2009-08-21 12:17:37 +0800 CST2009-08-21 12:17:37 +0800 CST 2009-08-21 12:17:37 +0800 CST

哪些命令会更改 Open Directory 密码?

  • 772

我将 Open Directory 理解为 OpenLDAP + SASL(密码服务器)+ Kerberos。OpenLDAP 似乎遵循 SASL 进行身份验证;我不知道 Kerberos。

我想从脚本更改用户密码,最好是远程更改,并且我希望正确更改密码。(即,在任何情况下,我都不希望用户拥有不同的密码,具体取决于他们对进入 Open Directory 的三个服务中的哪一个进行身份验证。)

我可以在dsimport未绑定到目录的机器上通过网络很好地进行操作,但是,当您尝试导入密码时(尽管将 AuthType 设置为 dsAuthMethodStandard:dsAuthClearText),它只有在没有密码的情况下才有效之前设定的。(我相信可以设置 Crypt 密码,但我担心这意味着只有 OD 的 LDAP 部分会知道当前密码。)

除了启动与服务器的 ssh 会话并在那里更改密码之外,我还能做些什么吗?如果我这样做,是否有任何命令可以让我在一行上指定多个用户及其新密码?

哪些命令可以更改所有打开的目录密码,有没有更喜欢的?

apropos password给了我这些有趣的结果:

  • kpasswd(1) - 更改用户的 Kerberos 密码
  • ldappasswd(1) - 更改 LDAP 条目的密码
  • lppasswd(1) - 添加、更改或删除摘要密码
  • passwd(1) - 修改用户密码
  • pwpolicy(8) - 获取和设置密码策略
  • saslpasswd2(8) - 设置用户的 sasl 密码
  • slappasswd(8) - OpenLDAP 密码实用程序

我会看一些手册页,我觉得这pwpolicy是最好的选择,但我很想知道使用这些手册是否有任何微妙之处(例如,不要更改 Kerberos 密码无需更改 LDAP 和 SASL 密码),并且如果它们中的任何一个在没有 ssh 会话的情况下远程工作。

password
  • 4 4 个回答
  • 11128 Views

4 个回答

  • Voted
  1. Best Answer
    Clinton Blackmore
    2009-08-29T09:47:26+08:002009-08-29T09:47:26+08:00

    我遇到的最方便的答案是将 passwd 命令与 dscl 结合使用。这是交互式会话的输出(密码由星号替换):

    $ dscl -u diradmin -p ces 
    Password: 
     > cd /LDAPv3/127.0.0.1/
    /LDAPv3/127.0.0.1 > auth diradmin *****
    /LDAPv3/127.0.0.1 > passwd Users/Atwo807 *****
    /LDAPv3/127.0.0.1 > passwd Users/Atwo249 *****
    /LDAPv3/127.0.0.1 > passwd Users/doesnotexist foobar
    passwd: Invalid Path
    <dscl_cmd> DS Error: -14009 (eDSUnknownNodeName)
    /LDAPv3/127.0.0.1 > exit
    Goodbye
    

    这是一个用于进行更改的python脚本。您将需要 pexpect 模块(sudo easy_install pexpect应该为您获取它;我认为您不需要安装开发工具)。

    #!/usr/bin/env python
    
    import pexpect
    
    def ChangePasswords(host, path, diradmin, diradmin_password, user_passwords, record_type='Users'):
        """Changes passwords in a Open Directory or similar directory service.
    
        host = the dns name or IP of the computer hosting the directory
        path = the pathname to the directory (ex. '/LDAPv3/127.0.0.1')
        diradmin = the directory administrator's shortname (ex. 'diradmin')
        diradmin_password = the directory administrator's password
        user_passwords = a dictionary mapping record names (typically, user's short
                         names) onto their new password
        record_type = the sort of records you are updating.  Typically 'Users'
    
        Returns a tuple.  The first entry is a list of all records (users) who
            failed to update.  The second entry is a list of all records (users)
            who successfully updated.
        """
    
        failed_list = []
        succeeded_list = []
        prompt = " > "
    
        child = pexpect.spawn("dscl -u %s -p %s" % (diradmin, host))
    
        if not (ReplyOnGoodResult(child, "Password:", diradmin_password) and
           ReplyOnGoodResult(child, prompt, "cd %s" % path) and
           ReplyOnGoodResult(child, prompt,
                            "auth %s %s"  % (diradmin, diradmin_password)) and
           ReplyOnGoodResult(child, prompt, None)):
            print "Failed to log in and authenticate"
            failed_list = user_passwords.keys()
            return (failed_list, succeeded_list)
    
        # We are now logged in, and have a prompt waiting for us
        expected_list = [ pexpect.EOF, pexpect.TIMEOUT,
                         '(?i)error', 'Invalid Path', prompt ]
        desired_index = len(expected_list) - 1
        for record_name in user_passwords:        
            #print "Updating password for %s" % record_name,
    
            child.sendline("passwd %s/%s %s" % (record_type, record_name,
                                                user_passwords[record_name]))
            if child.expect(expected_list) == desired_index:
                #print ": Succeeded"
                succeeded_list.append(record_name)
            else:
                #print ": Failed"
                failed_list.append(record_name)
                child.expect(prompt)
    
        child.sendline("exit")
        child.expect(pexpect.EOF)
    
        return (failed_list, succeeded_list)
    
    
    def ReplyOnGoodResult(child, desired, reply):
        """Helps analyze the results as we try to set passwords.
    
        child = a pexpect child process
        desired = The value we hope to see 
        reply = text to send if we get the desired result (or None for no reply)
        If we do get the desired result, we send the reply and return true.
        If not, we return false."""
    
        expectations = [ pexpect.EOF, pexpect.TIMEOUT, '(?i)error', desired ]
        desired_index = len(expectations) - 1
    
        index = child.expect(expectations)
        if index == desired_index:
            if reply:
                child.sendline(reply)
            return True
        else:
            return False
    

    您可以按如下方式使用它:

    # This example assumes that you have named the script given above 'pwchange.py'
    # and that it is in the current working directory
    import pwchange 
    
    (failed, succeeded) = pwchange.ChangePasswords("ces", "/LDAPv3/127.0.0.1", 
         "diradmin", "******", 
         { 'Atwo807' : '*****', 'Atwo249' : '*****', 
           'Nonexist' : 'foobar', 'Bad' : 'bad' })
    
    print failed, succeeded
    ['Bad', 'Nonexist'] ['Atwo249', 'Atwo807']
    
    • 5
  2. lukecyca
    2009-08-25T08:37:01+08:002009-08-25T08:37:01+08:00

    请记住,每个用户的登录钥匙串上的密码通常与他们的 Open Directory 密码保持同步。Mac OS X 足够聪明,可以使用在登录窗口输入的密码来验证用户身份,并解锁他们的钥匙串。如果这两个密码不同步,对于大多数用户来说将是不方便和混乱的。

    AFAIK,在服务器端更改 OD 密码的任何方法都无法修改用户的钥匙串密码。然而,AFP548 的人员为这个问题创建了一个名为Keychain Minder的解决方案,可以帮助遇到这种情况的用户。

    • 1
  3. drfoo
    2012-08-01T06:06:41+08:002012-08-01T06:06:41+08:00

    尝试使用

    dscl -u xxxxxx -P xxxxxxx /LDAPv3/127.0.0.1/ -authonly username
    

    接着

    dscl -u diradmin -P xxxxx /LDAPv3/127.0.0.1/ -passwd Users/username newpassword
    

    这些命令可以从本地机器或远程机器运行。远程客户端必须连接到目录实用程序中的目录。来自授权机器的远程身份验证检查看起来像

    dscl -u diradmin -P 123456 /LDAPv3/ldap.remote.com/ -authonly username
    

    我也用过

    dscl -u diradmin -P 123456 -url //LDAPv3/ldap.remote.com/ -authonly username
    
    • 1
  4. Clinton Blackmore
    2009-08-25T07:50:07+08:002009-08-25T07:50:07+08:00

    这是我学到的一些有用的东西:

    来自 OS X 10.5 的命令行管理文档,第 261 页,“管理开放目录密码”:

    管理 Open Directory 密码

    当用户帐户的密码类型为 Open Directory 时,用户可以通过 Kerberos 或 Open Directory 密码服务器进行身份验证。Kerberos 是一种网络身份验证系统,它使用受信任的服务器颁发的凭据。

    Open Directory Password Server 支持某些网络服务或用户的客户端应用程序所需的传统密码验证方法。可以将服务配置为不允许 Kerberos。在这种情况下,他们将密码服务器用于具有 Open Directory 密码的用户帐户。

    Kerberos 和 Open Directory 密码服务器都不会将密码存储在用户帐户中。Kerberos 和 Open Directory 密码服务器都将密码存储在目录域之外的安全数据库中,并且它们从不允许读取密码。密码只能设置和验证。

    开放目录密码服务器

    Password Server 使用标准的简单身份验证和安全层 (SASL) 技术来协商客户端和服务之间的身份验证方法。Password Server 支持多种身份验证方法,包括 APOP、CRAM-MD5、DHX、Digest-MD5、MS-CHAPv2、NTLMv1 和 NTLMv2、LAN Manager 和 WebDAV-Digest。

    Open Directory 还使用影子密码提供身份验证服务,支持与密码服务器相同的身份验证方法。

    关于 using ldappasswd,命令行管理文档进一步指出:

    Apple 建议使用 passwd 而不是 ldappasswd。有关详细信息,请参阅 passwd 手册页。

    man passwd指计算密码哈希的 OpenSSL 工具。获取您真正想要的 passwd 命令的手册页man /usr/share/man/man1/passwd.1.gz更有用。

    • 0

相关问题

  • 如何仅针对特定 OU 中的用户撤销更改密码权限?

  • AIX:如何在不设置 ADMCHG 标志的情况下以 root 身份更改密码?

  • 将活动目录中的密码历史记录重置为特定日期

  • 允许用户更改其 Active Directory 密码的 Web 界面

  • 通过 VPN 更改 Active Directory 密码

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    Windows 中执行反向 DNS 查找的命令行实用程序是什么?

    • 14 个回答
  • Marko Smith

    如何检查 Windows 机器上的端口是否被阻塞?

    • 4 个回答
  • Marko Smith

    我应该打开哪个端口以允许远程桌面?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    kch 如何更改我的私钥密码? 2009-08-06 21:37:57 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve