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

Vue integrates PDF.js to implement PDF preview and add watermark steps

Table of contents Achieve results Available plugi...

Tutorial on installing MySQL on Alibaba Cloud Centos 7.5

It seems that the mysql-sever file for installing...

Docker custom network detailed introduction

Table of contents Docker custom network 1. Introd...

MySQL 8.0.14 installation and configuration method graphic tutorial (general)

MySQL service 8.0.14 installation (general), for ...

Vue button permission control introduction

Table of contents 1. Steps 1. Define buttom permi...

Definition and function of zoom:1 attribute in CSS

Today I was asked what the zoom attribute in CSS ...

A brief discussion on the performance issues of MySQL paging limit

MySQL paging queries are usually implemented thro...

Using docker command does not require sudo

Because the docker daemon needs to bind to the ho...

How to make your browser talk with JavaScript

Table of contents 1. The simplest example 2. Cust...

Tutorial on deploying jdk and tomcat on centos7 without interface

1. Install xshell6 2. Create a server connection ...

WeChat Mini Program Lottery Number Generator

This article shares the specific code of the WeCh...

Two methods to implement MySQL group counting and range aggregation

The first one: normal operation SELECT SUM(ddd) A...

MySQL 5.7.20 free installation version configuration method graphic tutorial

I have seen many relevant tutorials on the Intern...

Metadata Extraction Example Analysis of MySQL and Oracle

Table of contents Preface What is metadata Refere...