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

Share 12 commonly used Loaders in Webpack (Summary)

Table of contents Preface style-loader css-loader...

MySQL storage engine basics

In the previous article, we talked about MySQL tr...

How to start multiple MySQL databases on a Linux host

Today, let’s talk about how to start four MySQL d...

Example code for implementing hexagonal borders with CSS3

The outermost boxF rotates 120 degrees, the secon...

Docker cleaning killer/Docker overlay file takes up too much disk space

[Looking at all the migration files on the Intern...

How to install mysql database in deepin 2014 system

Deepin 2014 download and installation For downloa...

Navicat for MySQL 15 Registration and Activation Detailed Tutorial

1. Download Navicat for MySQL 15 https://www.navi...

Nginx configuration PC site mobile site separation to achieve redirection

Use nginx to configure the separation of PC site ...

Specific steps to use vant framework in WeChat applet

Table of contents 1. Open the project directory o...

Mysql delete duplicate data to keep the smallest id solution

Search online to delete duplicate data and keep t...

Vue login function implementation

Table of contents Written in front Login Overview...

Summary of the use of special operators in MySql

Preface There are 4 types of operators in MySQL, ...

Install centos7 virtual machine on win10

1. Download VMware Workstation 64 version https:/...

Detailed explanation of Vue's keyboard events

Table of contents Common key aliases Key without ...