pw

How To Display A Custom Password Requirement Message For Linux Password Changes

I have implemented a new passwd policy and am forcing users to change their password. The problem I’m facing is I don’t they dont’ know what the password requirements are. How can I communicate this to them before they change their password using passwd?

That’s a great question, and it’s actually really simple. What we have to do is create our own custom script that displays the password requirements and then calls the passwd program. And we have to call the script whenever  a user types passwd command at the prompt.

Which passwd

On an Ubuntu system if we type “which passwd” we see the real location to our password program. We’ll need this location in order to call the real program in our script.

[LinuxAcademy $] which passwd

/usr/bin/passwd

Custom passwd Script With Password Requirements

#!/bin/bash

echo” *****password requirements*******”
echo “please use at least one lower case and upper case letter”
echo “please use at lease 2 charecters”
echo” but you cant use the * charecter”
echo “and one must be a ! ”
echo “and you must tap your head and pet your belly while you enter your password”

/usr/bin/passwd

Make It Work, By Editing Environment Variables

Edit one of your global environment configuration files. Either /etc/bashrc /etc/profile could be different depending on your distribution.

Create the alias line

alias passwd=”./location/to/custom_passwd”

Whenever someone logs into the system this alias is created. Once they type “passwd” at the command prompt your script is run, which displays the password requirements, then calls the real password program.