Modify User Password in Linux - Best method ?

In Linux, root privileges (or root access) refers to a user account that has full access to all files, applications, and system functions. 

You can use passwd command to change user password in Linux distribution. Password related information are stored at /etc/shadow file. If you are a normal user in your system then you can only change password of your own account. Only root account or users with sudo privileges can change password of another users.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related sudo queries.

In this context, we shall look into how to change user password in Linux. Also, we will cover how to change or set password of another users using sudo privileges.

How to Change Your User Password in Linux System ?

To change password of your own user account open terminal and run following command without any options:

$ passwd

It will prompt you to enter current password. Once it will be authenticate successfully you will be asked to enter new password and confirm password.

At next login you can use your new password instead of old one.

How to Change Another User's Password in Linux?

As we mentioned above that only root or sudo users can change another user's account password. Following is the basic syntax to change another user's password.

$ sudo passwd [username]

For example, assumes that you are logged in as a user with sudo privileges.

Now to change another user's account password run the passwd command followed by the username. 

Here we want to change the password for demouser then run the following command:

$ sudo passwd demouser

You will be prompted to enter and confirm the new password:

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

How to Force User to Change Password at Next Login ?

If you want to force users to change their account password at next login then you can it by adding expiry option. By default, passwords are set to never expire. Pass the --expiry option along with passwd command as given below:

$ sudo passwd --expiry demouser

This command will immediately expire a user account's password.

Once the demouser will try to login next time using old password it will force to set new password as given below:

WARNING: Your password has expired.
You must change your password now and login again!
Changing password for demouser.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Connection to closed.

After that once the user sets a new password the connection will be closed.

How to change Group Password in Linux ?

You can change password of group using -g option with passwd command. For example, to change the password of group colour, simply run following command:

$ sudo passwd -g colour

[Need assistance in fixing related Linux System errors? We can help you. ]

This article covers how to change own and another user account passwords. It's recommended that to change your password frequently and use a unique password for each account for security purpose. Basically, you will learn how to change a password on any Linux distribution, including Ubuntu, Debian, and CentOs.

To change a password on behalf of a user, first sign on or "su" to the "root" account. Then type, ``passwd user'' (where user is the username for the password you are changing). The system will prompt you to enter a password. Passwords do not echo to the screen when you enter them.

You can also change your own password, by typing ``passwd'' (without specifying a username). You will be prompted to enter your old password for verification, and then a new password.

How to Change a Password in Linux?

To change the password in Linux you need to open the terminal and type the following command:

$ sudo passwd

After executing the command, you will be asked to enter the new password twice. 

Related Posts