Check password using awk on /etc/shadow running as root on Linux

294 Views Asked by At

I am on an embedded linux box where I am the root user. I have set a password which is present in /etc/shadow file.

Now running as root user and using the following logic in a shell script, I am able to check if a password is set or not.

if [ `awk -F ':' '/^'$i':/ {print $2}' /etc/shadow` ] ; then 
   echo "Password is set" ;
   # How can I check, compare or retrieve the password now assuming that I am the root user with all privs
else 
   echo "Password is not set";
fi

Question:
I want to check and compare if password set is equal to "Password123". Is it possible to extend above logic to do that? Just check if the password is set to some default?

Please note that, I am running as the root user with all privileges on that embedded linux box running Fedora.

0

There are 0 best solutions below