Command To Change Password in Unix

Can you tell me command to change a password in Unix? How do I change a password in Unix operating system like macOS desktop or FreeBSD Unix server using the command line?

Introduction: To order to protect your Unix account, you must change your password at least every three to six months. A good password includes sequences of letters, numbers, and symbols that you enter to verify your identity to a Unix system. Once your identity verified, you will be granted access to server resources. In practice, one must use a password manager. A password manager can generate a password. It might be 30 to 40 characters long. It is far more difficult for a cracker to break a 40-character long password than an eight-character password. Apart from a good password on can use 2FA too to secure his/her password further.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time 2 minutes

Say hello to the Unix passwd command

All you have to do is type the following Unix passwd command to change your password:
You must provide an old password. Once old password verified, the Unix system will ask for a new password twice. As I suggested earlier, you must choose a complex password. All Unix password is case sensitive. The above command will change the password only on the laptop or server you are currently logged in using the ssh command or terminal session.

Command To Change Password in Unix

In short, to change your own password, type:
$ passwd

To change other users password, you must know root user password. A typical option is to use the su command or sudo command to become a root user and change the Unix user password:
$ sudo passwd
The file /etc/passwd contains a list of all users on Unix system. The passwd command contains other features, as well such as locking an user account and more.


In this quick tutorial you learned how to I change the password in Unix operating system using the passwd command. For more info see passwd command man page by typing the following command or online here and here:
$ man passwd

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • Raju K Mar 1, 2009 @ 7:16

    This solved my problem.

  • BSD Fan Dec 21, 2014 @ 7:16

    I googled “In Unix, how do I change my password?” and this page helped me to solve it on FreeBSD server. thanks!!!

  • Kyle Mcguire Jun 18, 2021 @ 8:00

    Thank you for quick tip. My problem solved. I had to change password for sftp user1 on HP-UX:
    sudo passwd sftpuser1

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum