1

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
4

1 Answer 1

1

sudoers Error: Anytime you're modifying the sudoers file, only edit it with visudo which will sanity check your changes and stop you from cutting your own head off. If you bork the sudoers file, could totally hose your access.

Permissions Error: This error can be a bit of a red herring...

I was just executing a script with sudo that kept failing with "permission denied" errors. I was sure it should have worked.

The reason why it was failing? I forgot to chmod 700 the file. As Homer Simpson would say, D'Oh!

So it was sort of a permissions error, but only as related to the mode of the file, rather than ownership of it.

Hope this helps others having Homer Simpson moments ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .