The GPG_TTY environment variable or github commit problem

By | July 25, 2021

I used a lot of different source control systems: SVN, CVS, Rational ClearCase, Perforce Helix, Bitbucket and others. Currently I am on github. Github looks indeed complex, even after Bitbucket which is based on git solution as well. Recently I cloned my repository on new Azure Linux virtual machine, everything was OK until commit step. Although I generated new GPG key, signed my changes the commit command failed with this error message:

# git commit -S -m “Some fix!”
error: gpg failed to sign the data
fatal: failed to write commit object

I spent several hours to find out that problem was related to GPG_TTY environment variable, which always should reflect the output of the tty command. In other word the GNU Privacy Guard must be informed about active terminal device. The currently used tty device for my Putty ssh session was /dev/pts/0:

# tty
# last | grep logged
root   pts/0   Fri Jul 16 13:16  still logged in

When I initialized GPG_TTY properly:

#export GPG_TTY=$(tty)
# echo $GPG_TTY

The git commit command passed through successfully.

Leave a Reply

Your email address will not be published. Required fields are marked *