0

My workplace has had me set up SSH git and GPG signing for my work. I have a few different GitHub accounts for different things, so I also have an SSH config set up in order to not have to do the same things over and over each time I set up/work on a new branch at work. My (relevant) SSH config is as follows:

Host renci
  HostName github.com
  User mwhicks-dev
  IdentityFile <<path to SSH>>
  IdentitiesOnly yes

I set up this host to use for all repositories where I'm running this account and particular SSH key (my work) so that I can just change the remote to use my host here.

I want to do a similar thing for GPG keys so that my commits are verified without me having to set up key verification every time I start on a new repository. Is there any way to set up my GPG key in this host, similar to the IdentityFile parameter?

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128

1 Answers1

3

SSH and GIT/GPG have nothing to do with each other, so you cannot configure which PGP key to use for signing commits in your .ssh/config. If you want to set up a PGP key to be used to sign commits you will have to configure git to do so.

You can set this up globally like this:

git config --global gpg.program gpg
git config --global commit.gpgsign true
git config --global user.signingkey <KEY-FINGERPRINT-HERE>

Where <KEY-FINGERPRINT-HERE> is the fingerprint of the key you want to use, which has to be already imported in gpg (see gpg --edit-key <your-mail> for the fingerprint).

You can also omit --global to configure different settings only for the current GIT repository that you are working on.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
  • You *can* actually use ssh's digital signature facilities with Git, but it's currently quite awkward. There's an in-progress set of changes to Git to make it smoother. It does seem extremely likely that the OP is really just using GPG. – torek Nov 09 '21 at 07:16
  • @torek yeah, indeed that was my assumption. – Marco Bonelli Nov 09 '21 at 14:30