Tóm tắt: tạo khoá ed25519, khai báo user.signingkey, bật commit.gpgsign, upload public key lên GitHub. Trên server không có TTY, đặt GPG_TTY.
Luồng hoạt động
flowchart LR A[git commit] --> B{commit.gpgsign?} B -- true --> C[gpg-agent ký bằng private key] C --> D[commit có chữ ký] D --> E[git push] E --> F[GitHub so với public key] --> G[Verified]
Lệnh
Tạo khoá
gpg --quick-generate-key "Nguyen Van A <a@example.com>" ed25519 sign 2y
gpg --list-secret-keys --keyid-format=long
# sec ed25519/ABCD1234EF567890 ...Cấu hình Git
git config --global user.signingkey ABCD1234EF567890
git config --global commit.gpgsign true
git config --global tag.gpgSign true
echo 'export GPG_TTY=$(tty)' >> ~/.bashrcUpload public key
gpg --armor --export ABCD1234EF567890
# Dán vào GitHub → Settings → SSH and GPG keys → New GPG keyKiểm tra
git log --show-signature -1
git verify-commit HEADLỗi thường gặp
| Triệu chứng | Nguyên nhân | Cách xử lý |
|---|---|---|
gpg failed to sign the data |
Không có TTY cho pinentry | export GPG_TTY=$(tty); với SSH dùng pinentry-curses |
GitHub hiện Unverified |
Email trong key khác email commit | git config user.email trùng UID của key |
No secret key |
user.signingkey sai ID |
Lấy lại ID bằng --keyid-format=long |
| Ký chậm ở lần đầu | gpg-agent chưa chạy | gpgconf --launch gpg-agent |