Detailed example of changing Linux account password

Detailed example of changing Linux account password

Change personal account password

If ordinary users want to change their personal account passwords, they only need to run the passwd command without any other commands:

$ passwd

Sample output:

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

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

NOTE: When you enter your password, it will not be displayed on the screen.

Change another user's password

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

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

$ passwd nick

Or use sudo command

$ sudo passwd nick

Output: You will be prompted to enter and confirm a new password

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

Force the user to change password at next login

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

$ sudo passwd --expire nick

This will immediately expire the password for the user account.

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

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.

After the user sets a new password, the connection is closed.

You may also be interested in:
  • Linux shell array and associative array usage examples
  • Android's implementation method of executing shell scripts in the Linux terminal to directly print the log of the currently running app
  • How to remotely batch execute Linux command programs using pyqt
  • Use of Zabbix Api in Linux shell environment
  • How to recover accidentally deleted messages files in Linux
  • Summary of solutions to common Linux problems
  • In-depth analysis of the Linux kernel macro container_of
  • Linux loading vmlinux debugging
  • Customization Method of Linux Peripheral File System
  • How to let DOSBox automatically execute commands after startup

<<:  express project file directory description and detailed function description

>>:  mysql executes sql file and reports error Error: Unknown storage engine'InnoDB' solution

Recommend

Detailed steps to install docker in 5 minutes

Installing Docker on CentOS requires the operatin...

Application of Hadoop counters and data cleaning

Data cleaning (ETL) Before running the core busin...

Use PSSH to batch manage Linux servers

pssh is an open source software implemented in Py...

Summary of MySQL date and time functions (MySQL 5.X)

1. MySQL gets the current date and time function ...

MySQL 5.7.21 winx64 installation and configuration method graphic tutorial

This article summarizes the notes for installing ...

Implementation of vscode custom vue template

Use the vscode editor to create a vue template, s...

CentOS 7.9 installation and configuration process of zabbix5.0.14

Table of contents 1. Basic environment configurat...

Solution to the error in compiling LVGL emulator on Linux

Table of contents 1. Error phenomenon 2. Error An...

Linux kernel device driver address mapping notes

#include <asm/io.h> #define ioremap(cookie,...

Detailed explanation of the basic commands of Docker run process and image

Table of contents 1. Run workflow 2. Basic comman...

Vue implements a complete process record of a single file component

Table of contents Preface Single file components ...

Detailed explanation of nginx configuration file interpretation

The nginx configuration file is mainly divided in...

Special commands in MySql database query

First: Installation of MySQL Download the MySQL s...