sign_and_send_pubkey: signing failed: agent refused operation

Solution 1:

I think your ssh-agent isn't working!
Perform the following commands...

eval `ssh-agent -s` 
ssh-add

Solution 2:

This may indicate file permission problems to your ~/.gnupg directory and underlying files!

Also make sure you have valid pinentry installed and operational, otherwise cannot validate PIN to your smartcard and this problem will occur as well!

The example ~/.gnupg/gpg-agent.conf should look like this:

enable-ssh-support
pinentry-program /Applications/MacPorts/pinentry-mac.app/Contents/MacOS/pinentry-mac

After changes are made to the configuration remember to gpgconf --reload.

Solution 3:

For gpg2.1

SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)" export SSH_AUTH_SOCK