Is there any way to set up an SSH config profile to perform GPG signing automatically?

610 Views Asked by At

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?

1

There are 1 best solutions below

2
On BEST ANSWER

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.