Script to unlock user

Use below bash script to unlock all or any user on system So please check user lock info .

1.root@node1:~# passwd -S user1
user1 L 10/09/2017 0 99999 7 -1                (L in ubuntu os)

2.[root@node2]# passwd -S user1
user1 LK 2017-12-28 0 99999 7 -1              (LK in centos os)

So before starting make sure that weather user has L or LK ( user lock info given in line 1 and 2 ).
Hence put same in  script as well .

#! /bin/bash

for username in `cat /etc/passwd |awk -F: ‘{print $1}’`
user=`passwd -S $username | awk ‘{print $2}’`
if [ “$user” = “LK” ] then
echo ” user locked”
passwd -u $username
echo “user is not locked”

Leave a Reply

Your email address will not be published. Required fields are marked *