ldappasswd

ldappasswd is a command-line utility used to change the password of an LDAP user. It communicates with an LDAP directory to update the user's password, and it can handle both simple authentication and SASL (Simple Authentication and Security Layer) authentication.

Usage of ldappasswd

Basic Usage

To change a user's password, you can use ldappasswd with the following basic command:

ldappasswd -x -D "cn=admin,dc=example,dc=com" -W -S "uid=username,dc=example,dc=com"
  • -x: Use simple authentication (default).

  • -D "cn=admin,dc=example,dc=com": Specify the bind DN for authentication.

  • -W: Prompt for the bind DN password.

  • -S "uid=username,dc=example,dc=com": Specify the target user's DN and prompt for the new password.

Common Options and Parameters

  • -H ldap://ldap.example.com: Specify the LDAP server URL.

  • -S: Prompt for the new password.

  • -A: Prompt for the current password of the user whose password is being changed.

  • -D "binddn": Use the specified bind DN to bind to the directory.

  • -w password: Use the specified bind DN password (insecure, use only in scripts).

  • -s secret: Use the specified new password (insecure, use only in scripts).

  • -a secret: Use the specified current password for the user (insecure, use only in scripts).

  • -ZZ: Require a secure TLS connection.

Example Commands

  1. Change Own Password

    Change the password of the currently authenticated user:

    ldappasswd -x -D "uid=username,dc=example,dc=com" -W -S

    This command will prompt for the current password of the user and the new password twice for confirmation.

  2. Change Another User's Password

    Admin changes another user's password:

    ldappasswd -x -D "cn=admin,dc=example,dc=com" -W -S "uid=username,dc=example,dc=com"

    This command will prompt for the admin's password and the new password for the user.

  3. Change Password with Current Password Prompt

    Change the user's password by also providing the current password:

    ldappasswd -x -D "uid=username,dc=example,dc=com" -W -A -S

    This command will prompt for the user's current password and the new password.

  4. Specify New Password Directly

    In a script, you might specify the new password directly (note the security risk):

    ldappasswd -x -D "cn=admin,dc=example,dc=com" -w adminpassword -s newpassword "uid=username,dc=example,dc=com"

    This command will change the user's password without interactive prompts.

Security Considerations

  1. Avoid Hardcoding Passwords: Hardcoding passwords in scripts or command lines can expose credentials. Prefer prompting for passwords or using secure methods to pass them to the command.

  2. Use Secure Connections: Always use secure connections (e.g., with -ZZ for StartTLS) when communicating with an LDAP server to protect credentials during transmission.

  3. Limit Privileges: Use the least privilege principle. Only bind with an account that has the necessary permissions to change passwords.

  4. Log Management: Ensure that command logs do not capture sensitive information like passwords.

Conclusion

The ldappasswd utility is a crucial tool for managing user passwords in an LDAP directory. Understanding its options and secure usage practices allows administrators to effectively manage password changes while maintaining the security and integrity of the directory service. Properly configured, ldappasswd facilitates the secure and efficient management of user credentials in LDAP environments.

Last updated