I'm running a bash script from terminal like
sudo sh /usr/local/ControlPanel/web/bin/login.sh admin myPassword
login.sh
#! /bin/bash
Username=$1;
Password=$2;
algorithm=$(grep $Username /etc/shadow | awk -F'$' '{print $2}')
salt=$(grep $Username /etc/shadow | awk -F'$' '{print $3}' | awk -F: '{print $1}')
password=$(grep $Username /etc/shadow | awk -F'$' '{print $4}' | awk -F: '{print $1}')
hashed='$'$algorithm'$'$salt'$'$password;
algorithmSalt='$'$algorithm'$'$salt;
plaintext=$(python -c 'import crypt; print crypt.crypt("'$Password'", "'$algorithmSalt'")')
if [[ $hashed == "$plaintext" ]]; then
echo "1|You have successfully loggedin.";
else
echo "0|Incorrect username or password.";
fi
/etc/sudoers.d/admin
admin ALL=(ALL) ALL
admin ALL=NOPASSWD:/usr/local/ControlPanel/web/bin/*
Without adding sudo I got the following error message
grep: /etc/shadow: Permission denied
After adding sudo I got the following error message
/etc/sudoers.d/admin: syntax error near line 1 <<<
sudo: parse error in /etc/sudoers.d/admin near line 1
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
sh
is usually notbash
.sh
toovisudo
so it tells you what mistakes there are:sudo visudo -f /etc/sudoers.d/admin