In the world of computing, security is one of the major concerns. One of the most basic security measures is setting strong passwords for user accounts. In Linux, managing user passwords is an essential task that requires proper understanding of the commands and tools used. This article provides a step-by-step guide on how to change a user password, change another user’s password, and force a user to change their password at next login in Linux.
The /etc/shadow file is a secure system file that contains encrypted passwords and password-related information for all users in a Unix-based operating system. The file is protected and only accessible by the root user and users with superuser privileges.
As a regular user, you are only able to change your own password. This can be done through the terminal or through a graphical user interface, depending on your operating system. The root user and users with sudo privileges, on the other hand, have the ability to change the passwords of other users and set password restrictions, such as password expiration dates and minimum password length requirements.
Changing Your Own Password in linux
One of the simplest ways to change your password in Linux is by using the “passwd” command. To change your password, follow these steps:
- Open the terminal and log in to your account.
- Type the following command in the terminal:
$ passwd
- You will be prompted to enter your current password. Once you have entered your current password, you will be asked to enter your new password.
- Enter your new password twice, then press enter. Your password will be changed.
Changing Another User’s Password in Linux
As a system administrator, you may need to change another user’s password. To do this, follow these steps:
- Open the terminal and log in as root.
- Type the following command in the terminal:
$ passwd <username>
- Replace
<username>
with the username of the user whose password you want to change. You will be prompted to enter a new password for the user. - Enter the new password twice, then press enter. The password for the specified user will be changed.
Setting an Expiry Date for a User’s Password
You can set an expiry date for a user’s password in Linux by using the “chage” command. To set an expiry date for a user’s password, follow these steps:
- Open the terminal and log in as root.
- Type the following command in the terminal:
$ chage -M <days> <username>
- Replace
<days>
with the number of days after which the password will expire and<username>
with the username of the user whose password you want to set an expiry date for. - The password for the specified user will now expire after the specified number of days.
Forcing a User to Change Their Password at Next Login
In addition to changing or managing user passwords, you may also need to force a user to change their password at their next login. This can be useful in cases where a password has been compromised or if a password needs to be reset for security reasons.
To force a user to change their password at their next login, follow these steps:
- Open the terminal and log in as root.
- Type the following command in the terminal:
$ sudo passwd --expire <username>
- Replace
with the username of the user who you want to force to change their password at their next login.<username>
- The user’s password will now be marked as expired and they will be required to change their password at their next login.
More Examples of passwd
Command
Here are some options for the passwd
command along with examples:
Deleting a Password
The -d
option can be used to delete the password for a specified user. This disables the user’s ability to log in to the system. The user will not be able to use the su
command to switch to a superuser account either. The password field for the user in the /etc/shadow
file will be set to !
or *
.
Example:
sudo passwd -d <username>
Expiring a Password
The -e
option can be used to expire the password for a specified user, forcing them to change their password the next time they log in. The user’s password field in the /etc/shadow
file will have the date of the last password change set to 0
.
Example:
sudo passwd -e <username>
Locking a Password
The -l
option can be used to lock the password for a specified user. The user will not be able to log in to the system until the password is unlocked. The password field in the /etc/shadow
file will be prefixed with an !
(exclamation point).
Example:
sudo passwd -l <username>
Unlocking a Password
The -u
option can be used to unlock a previously locked password. This will allow the user to log in to the system again.
Example:
sudo passwd -u <username>
By using the appropriate option with the passwd
command, you can effectively manage user passwords on a Linux system. It’s important to note that these options are only available to the root user or a user with superuser privileges.
Conclusion
Managing user passwords in Linux is an important task that helps maintain the security of user accounts and prevent unauthorized access to sensitive data. By following the steps outlined in this guide and using the relevant commands, you can easily change or manage user passwords in Linux.
Got questions or suggestions on the article? Don’t hesitate to leave a comment below. Your feedback is valuable to us and helps improve the content quality. And don’t forget to share this article with others who might find it useful. Looking forward to hearing from you!
If our tutorials helped you, please consider buying us a coffee. We appreciate your support!
Thank you for your support.