코딩굼벵이
구르는 중
코딩굼벵이
  • 분류 전체보기 (116)
    • [C_C++]이론 공부 (17)
      • 알고리즘 (11)
      • 이론+STL (6)
    • [C_C++]코딩테스트 연습 (45)
      • [프로그래머스] level 1 (26)
      • [프로그래머스] level 2 (5)
      • [백준] 일반 문제 (12)
      • 기타 (2)
    • Solana (28)
      • Documentation (9)
      • Validator - 공부 (10)
      • Validator - 실행 (devnet & te.. (6)
      • 그 외 (3)
    • React (4)
    • Linux (2)
    • Javascript (2)
    • 블록체인 기반 핀테크 및 응용 SW 개발 (8)
      • React (1)
      • Javascript (3)
      • Solidity (3)
      • 프로젝트 (1)
    • 기타 (10)

블로그 메뉴

  • 🌟 깃허브
  • 🌿 Portfolio(2021)
  • 홈
  • 태그
  • 방명록

티스토리

최근 글

태그

  • 솔라나
  • Immer #ContextAPI
  • 모니터링
  • Hooks #React
  • grafana
  • 밸리데이터

인기 글

전체 방문자
오늘
어제
hELLO · Designed By 정상우.
코딩굼벵이

구르는 중

[Gitlab][Linux] error: gpg failed to sign the data fatal: failed to write commit object 해결 방법
기타

[Gitlab][Linux] error: gpg failed to sign the data fatal: failed to write commit object 해결 방법

2025. 7. 18. 14:59
728x90

[ git commit, push하면 gpg 에러로 실패할 때 해결 방법 ]

기존에는 PAT만 써서 git commit, push를 하고 있었는데,
어느 시점부터 commit에 gpg key sign이 돼야 한다고 뜨더라.

- git log

2025-07-18 13:37:12.717 [info] > git push origin main:main [5357ms]
2025-07-18 13:37:12.717 [info] remote: GitLab: Commit must be signed with a GPG key
To https://gitlab.<repo-path>.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.<repo-path>.git'

 

gpg 서명을 쓰기 싫어서 git config에서 commit.gpgsign을 false로 껐더니,
이번엔 verified 된 email로 push commit을 해야 한다고 에러가 떴다.

remote: GitLab: You cannot push commits for 'kangyj@<company>.com'. You can only push commits if the committer email is one of your own verified emails.
To https://gitlab.<company-repo-path>.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.<company-repo-path>.git'

 

내 이메일 verified인데..

 

그래서 gpg key를 생성해서 commit 해보니 다음 에러가 떴다.

> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
error: gpg failed to sign the data
fatal: failed to write commit object

 

 

뭔가 현재 gitlab이 gpg key로 서명한 commit만 push가 가능하게 된 것 같다.

그래서 찾은 해결방법은 아래와 같다.

[environment]
OS : Ubuntu 22.04
git --version : 2.34.1
gpg --version : gpg 2.2.27

1. gpg key 생성

gpg --full-generate-key
  • 권장 옵션:
    • RSA and RSA
    • Key size: 4096
    • Expire: 0 (영구)
  • Name/email 입력
  • passphrase 입력

이 때 입력한 passphrase를 기억해뒀다가 서명할 때 뜨는 창에 입력해야 함.

2. gpg id 확인

gpg --list-secret-keys --keyid-format LONG <email>

 

- 결과 예시

/home/yourname/.gnupg/secring.gpg
---------------------------------------
sec   4096R/ABCDEF1234567890 2023-01-01 [SC]
uid                          Your Name <your@email.com>

여기 ABCDEF1234567890 자리에 있는 게 gpg id.

 

3. gpg key 등록

gitlab 프로필 > preference > gpg keys 에서 아래 command 결과 (-----BEGIN ~ -----END 줄까지) 붙여넣기

gpg --armor --export <gpg id>

 

4. ~/.gitconfig에 아래 내용 포함

[user]
        signingkey = <gpg id>
        email = <your_email>
        name = <your_name>
[commit]
        gpgsign = true
[gpg]
        program = gpg

 

(git.config --global user.signingkey <gpg id> 같은 식으로 등록해도 됨)

 

5. ~/.bashrc 에 아래 줄 추가

export GPG_TTY=$(tty)

source ~/.bashrc 로 적용

 

6. 서명 잘 되는지 테스트

echo "test" | gpg --clearsign

잘 되면 commit -> push가 가능해진다.

 

+ 생성한 gpg key를 다른 환경에서도 사용하고 싶을 때

1. gpg key 내보내기

gpg --export ABCDEF1234567890 > ~/public.key
gpg --export-secret-key ABCDEF1234567890 > ~/private.key

ABCDEF1234567890 에 gpg --list-keys에서 나온 key id를 넣으면 됨.

 

2. gpg key를 옮길 환경으로 보내기

ex)

scp ~/public.key root@<ip>:/root/

 

3. gpg key 가져오기

gpg --import ~/public.key
gpg --import ~/private.key

 

4. 서명 잘 되는지 테스트

echo "test" | gpg --clearsign

잘 되면 마찬가지로 commit -> push가 가능해진다.

이 환경에서도 ~/.gitconfig, ~/.bashrc 설정하는 것 잊지 말기!

저작자표시 비영리 변경금지 (새창열림)

'기타' 카테고리의 다른 글

[Github] Mac OS에서 Github에 프로젝트 올리기  (0) 2022.08.31
[웹 개발] 프론트와 백에서의 CORS 문제 해결하기  (0) 2022.08.12
[Javascript] 비동기 처리, Promise, async/await  (0) 2022.07.13
SQL과 NoSQL의 차이, 장단점  (0) 2022.06.23
websocket과 socket.io 의 차이  (0) 2022.06.22
    '기타' 카테고리의 다른 글
    • [Github] Mac OS에서 Github에 프로젝트 올리기
    • [웹 개발] 프론트와 백에서의 CORS 문제 해결하기
    • [Javascript] 비동기 처리, Promise, async/await
    • SQL과 NoSQL의 차이, 장단점
    코딩굼벵이
    코딩굼벵이
    구르는 재주 연마 중

    티스토리툴바