본문 바로가기
OpenSource

gpg를 설정 해보자! (github verified)

by egas 2021. 5. 13.

 

https://docs.github.com/articles/about-gpg/


gpg를 설정 해보자! commit의 Verified가 gpg와 연관이 있었다니 지금이라도 알게되어서 다행이다.

https://help.github.com/articles/generating-a-new-gpg-key/

1. Homebrew 를 통해 gpg 패키지를 설치한다.

brew install gpg

2. gpg 키 관리 프로그램인 GPG-SUITE를 설치한다.

brew cask install gpg-suite

 

만약, 아래와 같은 에러가 나온다면

brew cask install gpg-suite
Error: Unknown command: cask

다음과 같이 입력하자!

brew install --cask gpg-suite

 

3. 터미널에서 key 생성

gpg --full-generate-key
  • 암호화 방식 선택 (권장: 1)
  • 암호화 키 크기 선택: 4096
  • 키 유효기간 설정 (권장: 0) // Enter 입력하여 패스
  • 이름, 이메일, 코멘트 입력
  • 이후 보안 암호 문구 작성 창에서 암호 입력 (이후 첫 commit시 입력하는 암호이다.)

 

gpg (GnuPG) 2.3.1; Copyright (C) 2021 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

gpg: directory '/Users/tonybyeon/.gnupg' created
gpg: keybox '/Users/tonybyeon/.gnupg/pubring.kbx' created
Please select what kind of key you want:
   (1) RSA and RSA
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
   (9) ECC (sign and encrypt) *default*
  (10) ECC (sign only)
  (14) Existing key from card
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 4096
Requested keysize is 4096 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: HoChan Lee
Email address: hochan049@gmail.com
Comment:
You selected this USER-ID:
    "HoChan Lee <hochan049@gmail.com>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O

 

위의 과정을 마치고 나면 키가 생성된다.

아래 명령어를 이용하여 생성한 키를 확인할 수 있다.

 

gpg --list-secret-keys --keyid-format LONG

 

gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
/Users/tonybyeon/.gnupg/pubring.kbx
-----------------------------------
sec   rsa4096/3FD339327D0A0680 2021-05-06 [SC]
      98B2B33E1A80ADD0BD90DCB83FD339327D0A0680
uid                 [ultimate] HoChan Lee <hochan049@gmail.com>
ssb   rsa4096/CF74F0D5874A831A 2021-05-06 [E]

 

3FD339327D0A0680의 부분을 복사하고 아래 명령어를 실행한다.

 

gpg --armor --export 3FD339327D0A0680

 

-----BEGIN PGP PUBLIC KEY BLOCK-----부터 -----END PGP PUBLIC KEY BLOCK——를 포함해서 모두 복사한다.

 

4. GitHub 에 GPG Key 등록

 

GitHub - Settings - SSH and GPG keys

GPG Keys 부분의 new GPG key 버튼을 클릭한뒤 복사한 키를 등록한다.

 

5. Git 에 GPG Key 등록

 

아래 명령어를 통해 ~/.gitconfig에 gpg 정보를 추가한다.

 

$ git config --global user.signingkey 3FD339327D0A0680
$ git config --global gpg.program $(which gpg)

 

등록이 완료됐다.

이후 commit 부터는 -S 플래그를 넣음으로 서명을 적용한 Commit 을 보낼 수 있다.

 

git commit -S

 

-S 플래그를 넣는것이 귀찮은가?

아래 명령어로 항상 서명을 적용하자.

 

git config --global commit.gpgsign true

 

오..! 추가됐다.

 

 

Error Handling

giterror: gpg failed to sign the data
fatal: failed to write commit object

 

commit 시 오류가 발생하면 아래 내용을 ~/.zshrc 또는 ~/.bashrc에 추가해준다.

 

export GPG_TTY=$(tty)

 

~/.gitconfig가 올바르게 설정 됐는지 확인해보자!

cat ~/.gitconfig
[user]
        email = hochan049@gmail.com
        name = hochan222
        signingkey = 3FD339327D0A0680
[filter "lfs"]
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
        required = true
[gpg]
        program = /usr/local/bin/gpg
[commit]
        gpgsign = true

 

gpg 재시작

 

gpgconf --kill gpg-agent

 

728x90

'OpenSource' 카테고리의 다른 글

ripgrep 소개  (0) 2021.07.30
gource 소개  (0) 2021.07.28
Github changelogs  (0) 2021.07.18
gh-pages 로 배포하기  (0) 2021.07.17
Github multiple authors  (0) 2021.07.17

댓글