Home > Operation and Maintenance > Linux Operation and Maintenance > How to change account password in Linux? (code example)

How to change account password in Linux? (code example)

青灯夜游
Release: 2019-01-24 17:08:59
Original
4444 people have browsed it

Both Linux and UNIX-like operating systems use the passwd command to change user passwords. This article will introduce how to use the passwd command to change user passwords. I hope it will be helpful to you.

How to change account password in Linux? (code example)

In Linux, encrypted user passwords and other password-related information are stored in the /etc/shadow file. You can use the passwd command to change the user password.

When changing your password, be sure to use a strong and unique password. Having a strong password is the most important thing you can do to protect your account. Strong passwords usually contain at least 16 characters, using at least one uppercase letter, one lowercase letter, one number and one special character. [Video tutorial recommendation: Linux tutorial]

Change personal account password

Ordinary users want to change their personal Account password, you only need to run the passwd command without any other commands:

$ passwd
Copy after login

Sample output:

Changing password for nick
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Copy after login

The system will prompt us to enter the current password first. If the password is correct, it will ask Re-enter and confirm the new password. The next time you log in to the Linux system, you can use the new password to log in.

Note: When entering the password, the password will not be displayed on the screen.

How to change account password in Linux? (code example)

Change another user’s password

As a normal user, you can only change your own password password. However, root users and users with sudo permissions can change the passwords of other users.

We need to log in as the root user, type the following command to change the password of user nick:

$ passwd nick
Copy after login

Or use the sudo command

$ sudo passwd nick
Copy after login

Output: The system will prompt for input and confirmation New password

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Copy after login

Force user to change password on next login

By default, passwords are set to never expire. If you want to force a user to change their password on the next login, you need to use the passwd command with --expireoption, followed by the user's username, for example:

$ sudo passwd --expire nick
Copy after login

This will immediately cause the user account's password to expire.

The next time the user tries to log in with the old password, a message will be displayed forcing them to change their password:

$ ssh nick@192.168.121.209
Copy after login

Output:

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

After the user sets a new password, it will be closed connect.

The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of How to change account password in Linux? (code example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template