One of the basic tasks that a Linux user must know is how to change their account password. This can be necessary for various reasons, such as to comply with security policies or to simply update an old password that is no longer secure. Moreover, it is essential to use a strong password for your user account to protect your personal files and data from unauthorized access. It is recommended to change your password regularly to further enhance security. In this tutorial, we will learn how to change the password of a user in Ubuntu system. Whether you are a beginner or an experienced Linux user, this guide will help you to change the password of a user in Ubuntu and provide some tips for creating a secure password.
Change User Password in Ubuntu
The passwd command in Linux is used to How To Change Linux Credentials. To change the password of a user, you will need to log in to the system as that user or as a superuser.
To change the password of the currently logged in user, simply run the passwd command without any arguments:
It will prompt you to type the user’s password and then to set the new password. Make sure to pick a strong password that is hard to guess and meet the password policy of your system.
To change password of other users, you will require sudo privileges. Use the passwd command followed by the user name to change the password:
$ sudo passwd <username>
This will ask you to type new password for the specified user. Let’s say to change the password for the user “genie”, you would use:
$ sudo passwd genie
Forcing a User to Change Its Password
Instead of changing a user’s password yourself, you can also force a user to change his password at next login. Keep in mind that you must be logged in as an administrator or have sudo privileges to use the chage command.
There are two ways to force a user to change his password:
Using the passwd Command
Use the -e or –expire flag to expire the user’s password immediately. The next time user logs in, he will be prompted to change his password.
sudo passwd -e <username>
The next time user logs in; he will be asked to change his password.
Using the chage Command
You can also force a user to change his password using the chage command. To do so, use chage command with the -d flag as follows:
sudo chage -d 0 <username>
The next time user logs in, he will be asked to change his password.
Additionally, you can use the -M or –maxdays flag to set the maximum number of days during which a password will remain valid. When the password reaches the maximum age, the user will be asked to change his password. For instance, to expire the user’s password after every 30 days, the command would be:
sudo chage -M 30 <username>
Changing Password Using the Graphical User Interface (GUI):
If you prefer GUI, you can use the Settings application in your Linux distribution to change the password of a user.
Open the settings app from the main applications menu or using the right-click menu (context menu). In the Settings window, go to Users tab.
Click Unlock at upper right corner and provide administrator password.
Then, click the user account whose password you want to reset. Under the Authentication & login section, click the dotted icon next to the Password field.
It will open the Change Password window. Select Set a password now option and type new password. Once done, click Change to save the changes.
You can also allow a user to change its password on his next login by selecting the first option.
To change the administrator password, you will have to first provide his current password. Then you will be able to set a new password for the administrator account.
Tips for Creating a Secure Password:
Here are some tips to create a secure password:
- Use upper and lowercase letters with at least one number and special character.
- Avoid using everyday words or personal info like your name, date of birth, home address or phone number.
- Password should be at least 8 characters long.
- Use a different password for each account.
- Use a password vault to create and store strong passwords.
This guide covered how to change a user password in Ubuntu through command line and GUI. This guide also covered how to force a user to change his password and some tips for generating a secure password.