passwd - macOS


Overview

The passwd command allows you to change the password for a specified user account on your macOS system, including the root (administrator) account.

Syntax

passwd [options] [username]

Options/Flags

  • -a: Append to the end of the current password.
  • -d: Delete the specified user’s password, effectively disabling the account. Note: Do not use this option on the root account.
  • -h: Display help information and exit.
  • -l: Lock the specified user’s account.
  • -n: Do not prompt for the current password.
  • -u: Unlock the specified user’s account.

Examples

  • To change your own password:

    passwd
    
  • To change another user’s password (requires sudo privileges):

    sudo passwd username
    
  • To disable a user’s account:

    sudo passwd -d username
    

Common Issues

Error: Incorrect password.

Ensure that you are entering your current password correctly.

Error: Permission denied.

Ensure that you have proper permissions to change the specified user’s password. If changing the root password, you must be logged in as root.

Integration

The passwd command can be combined with other macOS commands for automated password management. For example:

echo "newpassword" | sudo passwd username