Command To Change Password in Unix

last updated in Categories ,

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.

Say hello to the Unix passwd command

All you have to do is type the following Unix passwd command to change your password:
passwd
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
Command To Change Password in Unix
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.

Conclusion

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at www.nixcraft.com

Historical Comment Archive

2 comment

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

    Have a question? Post it on our forum!