It is a common error this users generally encounter when they try to execute a brew command as sudo and shown below are an Example of the error looks like:
Debjit-sahas-mac-mini:mcrypt debjit$ sudo brew link mcrypt
Password:
Sorry, try again.
Password:
Error:cowardly refusing to ' sudo brew link '
You can use a brew with sudo and only if the brew executable are owned by root.
However, this is both not recommended and completely unsupported so does at
Your own risk.
First find out what's the current ownership of the installed package of brew (you'll need this info in the last step)
Ls-al ' which brew '
Change the user and group of brew to root and wheel respectively:
sudo chown root:wheel ' which brew '
Now execute your brew command as root, for eg. sudo brew link mcrypt. Lastly, revert back the ownership of brew to what are had found out in step 1 above
sudo chown: ' Chown brew '
How to Fix cowardly refusing to Sudo error in Brew–mac OS X