Home Linux & Systems Cybersecurity Cloud & DevOps Networks & Infrastructure SIEM & Monitoring DFIR & Threat Intel Development & Other All categories Projects About Tools

Script to add expiration to GNU/Linux user passwords

Leer en espanol
Script to add expiration to GNU/Linux user passwords

Table of contents

So this time ===

By default, when we create a user and add a password, it does not expire unless we configure it using the -x option, which we will see another time.

So on this occasion I bring a very simple script with which, using the command chage adds the expiration to the password of the indicated user.

Bash
#!/bin/sh

#rokitoh
###############################################################

###############################################################

######## Script de tiempo de vida de claves y usuarios #####

####### rokitoh #####

###### #####

###############################################################

###############################################################
usage()

{

cat << EOF

USO: $0 -E <FECHA> -u <Usuario>
Ejemplo menú de opciones
OPCIONES:

-E Establece la fecha de caducidad de la cuenta

-u Indica el usuario al que establecera la caducidad en la cuenta.

EOF

}
#Declaramos todas las variables que se van a usar para guardar los parametros

fecha=

usuario=
#Usamos el getopts para guardar los parametros en variables

while getopts “E:u:” OPTION
do

case $OPTION in
E)

fecha=$OPTARG
;;
u)

usuario=$OPTARG

;;
*) echo «Opción inválida: -$OPTARG» ;;
esac

done
#Comprobamos que se han introducido los parametros obligatorios
if [ -z $fecha ] || [ -z $usuario ]

then

usage

exit 1

fi
#Se agrega la fecha al usuario indicado
chage -E $fecha $usuario
#Lista la inormacion del usuario

chage -l $usuario

Example of use: 

text
/usr/bin/userexpiration -E 2015-03-31 -u rokitoh

As we can see in the previous command we indicate that the user rokitoh access will expire on the day 31/03/2015

Greetings, rokitoh.

:wq!

Comments