I'm running a bash script from terminal like

sudo sh /usr/local/ControlPanel/web/bin/login.sh admin myPassword


#! /bin/bash


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}')


plaintext=$(python -c 'import crypt; print crypt.crypt("'$Password'", "'$algorithmSalt'")')

if [[ $hashed == "$plaintext" ]]; then 
    echo "1|You have successfully loggedin.";
    echo "0|Incorrect username or password.";


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

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 ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.