Enter passphrase with pinentry in Terminal via SSH connection

By default, when you're running a gpg operation which asks for your key's passphrase, an external passphrase window is opened (pinentry).

In some cases however, you may like to enter the password directly in the Terminal, for example, when you're logged in via SSH.

In order to do that, add the following commands to your .bashrc or .profile file.

export GPG_TTY=$(tty)
if [[ -n "$SSH_CONNECTION" ]] ;then