Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Bananamilk452/3d337318ba06c2e8afc4375047a65f2e to your computer and use it in GitHub Desktop.
Save Bananamilk452/3d337318ba06c2e8afc4375047a65f2e to your computer and use it in GitHub Desktop.
Keybase와 Github-Git GPG Key 연동하기

0. 왜 GPG 있는데 굳이 키베이스? 그리고 이거 왜 하냐?

연동이 된다. 키를 키베이스에서 보관해준다. 퍼블릭 키를 키베이스 서버에서 제공해준다.

Github은 커밋한 사용자의 진위 여부를 가리지 않는다. 남이 당신의 계정 명의로 커밋을 할 수도 있다. Github에 내 GPG 키를 올려서 Git에서 커밋할 때 서명하면 Github에서 확인된 사용자의 커밋인지 알려준다.

1. 키베이스 설치 & 로그인

키베이스 사이트

2. 키베이스 CLI & GPG 키 생성하기

경로: %localappdata%/Keybase.exe 또는 자신의 키베이스 설치 경로

keybase pgp gen --multi

CLI에서 말하는 대로 각종 정보 입력하기. Y/N 선택지는 다 Yes.

- INFO PGP User ID: lol <lol@gmail.com> [primary]
- INFO Generating primary key (4096 bits)
- INFO Generating encryption subkey (4096 bits)
- INFO Generated new PGP key:
- INFO   user: lol <lol@gmail.com>
- INFO   4096-bit RSA key, ID 565A65E203FC12C4, created 2021-06-21
- INFO Exported new key to the local GPG keychain

이렇게 나온다면 생성 완료.

3. 내부 GPG 스토리지에 Certificate import하기

경로: C:\Program Files\Git\usr\bin 또는 자신의 Git 설치 경로

자신이 자체적으로 설치한 GPG가 있다면 경로는 상관없다, 하지만 GPG와 Git의 자체 GPG 인증서 스토리지는 다를 수도 있다! 이 점에 유의하자.

이 명령어는 keybase pgp 스토리지에 인증서가 하나만 있을 경우에만 유효한다, 여러개의 인증서가 있으면 -q로 key를 특정해주자.

keybase pgp export | gpg --import
keybase pgp export -s | gpg --import --allow-secret-key-import

4. Github에 GPG 키 업로드하기

깃허브 키 설정 페이지에 들어가서 Add New를 누르고 Public 키를 입력해준다.

Public 키는 키베이스 프로필에서 찾거나, 아래의 명령어를 입력해서 가져오자.

keybase pgp export 혹은 keybase pgp export -q <Keybase Key ID>

5. Git에서 인증서 지정하고 GPG 서명 활성화 해주기

먼저 인증서 퍼블릭 키를 가져온다.

gpg -k

------------------------------------------------
pub   rsa4096 2021-06-21 [SC] [expires: 2037-06-17]
     <당신의 퍼블릭 키 ID>
uid           [ unknown] Junsu Yun <bananamilk452@gmail.com>
uid           [ unknown] Junsu Yun <starterdroid@outlook.com>
sub   rsa4096 2021-06-21 [E] [expires: 2037-06-17]

그리고나서 Git에서 인증서 키를 지정하고 GPG 서명을 활성화해준다.

git config user.signingkey <당신의 퍼블릭 키 ID>
git config commit.gpgsign true

이제 앞으로 커밋할 때 인증서 비밀번호를 물어볼 것이다.

커밋 기록에서 이렇게 뜨면 성공이다. 와!

> git log --show-signature
commit 2b707e1a642d7cf01a1851c699d3c2668b9fa811 (HEAD -> main, origin/main)
gpg: Signature made Tue Jun 22 00:07:09 2021
gpg:                using RSA key 38747363066B9A5C9428F0EEA131EB43BBF94504
gpg: Good signature from "Junsu Yun <bananamilk452@gmail.com>" [unknown]
gpg:                 aka "Junsu Yun <starterdroid@outlook.com>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 3874 7363 066B 9A5C 9428  F0EE A131 EB43 BBF9 4504
Author: Bananamilk452 <bananamilk452@gmail.com>
Date:   Tue Jun 22 00:07:04 2021 +0900

    lol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment