Merge pull request #32 from viechoco/main

chore: Translate Jasmerah1966's Git articles
This commit is contained in:
jasmerah1966 2023-10-26 12:15:12 +07:00 committed by GitHub
commit e05035cab3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 364 additions and 1 deletions

View file

@ -0,0 +1,221 @@
---
title: "How To Create 'Verified' (Sign) Git Commit Using SSH or GPG Signature (Linux)"
description: "How to add a 'Verified' commit message to GitHub using SSH Signing Key or GPG Signing Key, step by step."
# linkTitle:
date: 2023-10-26T10:33:43+07:00
lastmod:
draft: false
noindex: false
# comments: false
nav_weight: 1000
# nav_icon:
# vendor: bootstrap
# name: toggles
# color: '#e24d0e'
series:
# - Tutorial
categories:
- TIL
tags:
- Git
- GitHub
- SSH
- PGP
images:
# menu:
# main:
# weight: 100
# params:
# icon:
# vendor: bs
# name: book
# color: '#e24d0e'
authors:
- jasmerah1966
- vie
---
How to add a **"Verified"** commit message to **GitHub** using **SSH Signing Key** or **GPG Signing Key**.
<!--more-->
---
If you often visit the _commit history_ page of a **GitHub** repository, you may find that there are some _commit messages_ with **"Verified"** badge, unlabeled, or even **"Unverified"** with an orange colored badge.
This feature on GitHub indicates that the _commit_ or _tag_ comes from an authentic source and has been verified by GitHub. This is important so that other users who use the repository are sure that the changes made to the repository are indeed from verified sources.
Until this article was written, there were 3 ways to sign the _commit_ message: by using **GPG signature**, **SSH signature**, and **S/MIME signature**. From those three methods, I want to share my experience using the GPG and SSH signatures method to _signing_ commit.
To follow steps in this article, make sure that your current Git configuration is working without any problems. If you have never set up Git, follow my previous article: [How To Use Git Using SSH Protocol For GitHub]({{< ref "/tutorials/how-to-use-git-using-ssh-protocol-for-github/index.md" >}}).
## Using SSH key signature
The easiest way is using the SSH signature method. You can use the SSH key that you already use for the __Authentication key__ and upload the same _public key_ to use as the __Signing key__.
> _Note: To use the SSH Key Signature method, you need to use Git `2.34` and above._
### Adding SSH key as signing key
To add an SSH key as a __Signing key__ in your GitHub account:
1. Go to __"Settings"__ > __"SSH and GPG keys"__ > Click the __"New SSH key"__ button.
2. Fill in __"Title"__ with whatever you can easily remember to identify your _SSH key_.
3. In the __"Key type"__ section, select __"Signing Key"__.
4. Finally return to the terminal and _paste_ the contents of __SSH public key__ into _textarea_ __"Key"__. After that, click the __Add SSH key"__ button.
### Change the Git configuration on your local computer
After the SSH Signing key has been added to your GitHub Account, you need to change the Git `gpg.format` configuration value to `ssh` by running the following command:
```shell
git config --global gpg.format ssh
```
Finally, update the `user.signingkey` config and enter the location where the **SSH PUBLIC KEY** that you have uploaded is:
```shell
git config --global user.signingkey ~/.ssh/github_key.pub
```
> _Note: Change `~/.ssh/github_key.pub` with the actual location your PUBLIC KEY is stored._
## Using GPG key signature
You can use GPG Key Signature to sign _commit_ messages.
### Generating GPG key
If you don't have a _GPG key pair_ yet, you can create one by running the following command:
```shell
gpg --full-generate-key
```
After executing the command above, you will be asked to complete the information, including:
1. Type: Choose any, I recommend just using the default: `RSA and RSA`.
2. Key size: Fill in between 1024 to 4096. Default 3072. I recommend using `4096`.
3. How long the GPG key is valid: I recommend using the default (`0`, no expiration date).
4. Enter Name and email information. Pay attention when filling in email information, **make sure the email you enter is the same as the email you use on GitHub**.
5. Enter `passharse` your GPG key.
Example output from the `gpg --full-generate-key` command:
```plain
gpg (GnuPG) 2.2.41; Copyright (C) 2022 g10 Code GmbH
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (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) 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: Jasmerah1966
Email address: jasmerah1966@example.com
Comment: GPG sign key untuk GitHub
You selected this USER-ID:
"Jasmerah1966 (GPG sign key untuk GitHub) <jasmerah1966@example.com>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: revocation certificate stored as '/home/jasmerah1966/.gnupg/openpgp-revocs.d/F5FEE1EF836C62F5361A643B156C485C2EB2C1D6.rev'
public and secret key created and signed.
pub rsa4096 2023-10-23 [SC]
F5FEE1EF836C62F5361A643B156C485C2EB2C1D6
uid Jasmerah1966 (GPG sign key untuk GitHub) <jasmerah1966@example.com>
sub rsa4096 2023-10-23 [E]
```
### Getting your GPG keys information
To see your GPG key list (having a secret key), you can run the following command:
```shell
gpg --list-secret-keys --keyid-format=long
```
Example output from the command above:
```plain
/home/jasmerah1966/.gnupg/pubring.kbx
-------------------------------------
sec rsa4096/156C485C2EB2C1D6 2023-10-23 [SC]
F5FEE1EF836C62F5361A643B156C485C2EB2C1D6
uid [ultimate] Jasmerah1966 (GPG sign key untuk GitHub) <jasmerah1966@example.com>
ssb rsa4096/04951FB42332019F 2023-10-23 [E]
```
Then run the following command to get the GPG key in **ASCII armor** format:
```shell
gpg --armor --export 156C485C2EB2C1D6
```
> _**Note**: Change my key ID above (`156C485C2EB2C1D6`) with your key ID._
Copy your GPG key (starting from `-----BEGIN PGP PUBLIC KEY BLOCK-----` to `-----END PGP PUBLIC KEY BLOCK-----`) which after this step, you need to add to your GitHub account.
### Adding GPG to Yyur GitHub Aacount
1. Go to __"Settings"__ > __"SSH and GPG keys"__ > Click the __"New GPG key"__ button.
2. Fill in __"Title"__ with whatever you can easily remember to identify your _GPG key_.
3. Enter your GPG key into _textarea_ __"Key"__. After that, click the __Add GPG key"__ button.
## Signing your commit
If it has been set correctly, you can commit with the command `git commit -S` or `git commit -S -m 'Your commit message'`
For signing with **S/MIME** I have never had the opportunity to try. Maybe if anyone wants to add it, please add it by doing a pull request.
I hope this helps.
> _**Catatan**: Ubah key ID milik saya diatas (`156C485C2EB2C1D6`) dengan key ID milik Anda._
Copy GPG key Anda (diawali dari `-----BEGIN PGP PUBLIC KEY BLOCK-----` sampai `-----END PGP PUBLIC KEY BLOCK-----`) yang setelah ini perlu Anda tambahkan ke akun GitHub Anda.
### Menambahkan GPG Ke Akun GitHub Anda
1. Masuk ke __"Settings"__ > __"SSH and GPG keys"__ > Klik tombol __"New GPG key"__.
2. Isi __"Title"__ dengan apapun yang mudah Anda ingat untuk mengidentifikasi _GPG key_ Anda.
3. Masukkan GPG key Anda ke _textarea_ __"Key"__. Setelah itu klik tombol __Add GPG key"__.
## Melakukan Signing Commit
Jika sudah disetting dengan benar, Anda bisa melakukan commit dengan perintah `git commit -S` atau `git commit -S -m 'Pesan commit kamu'`
Untuk signing dengan **S/MIME** saya belum pernah memiliki kesempatan untuk mencoba. Mungkin jika ada yang ingin menambahkan silahkan ditambahkan dengan melakukan pull request.
Semoga membantu.

View file

@ -44,6 +44,19 @@ Proses authentikasi menggunakan protokol SSH memanfaatkan __SSH public dan priva
Kali ini saya ingin berbagi cara menggunakan protokol SSH sebagai metode autentikasi ke spesifik provider, yaitu GitHub. Namun sebelum memulai, pastikan `git` dan `ssh` sudah terinstall di komputer Anda dan Anda sudah memiki akun di GitHub.com.
## Global Config
> _**Catatan**: Jika Anda sudah pernah mensetting global config untuk Git, Anda bisa melewati langkah ini._
Jalankan perintah berikut untuk mensetting nama dan email Anda saat melakukan _commit_:
```shell
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
```
Ubah `John Doe` dan `johndoe@example.com` sesuai dengan Akun milik Anda.
> _**Catatan**: Pastikan alamat email sesuai dengan alamat email yang Anda gunakan dan sudah terverifikasi di GitHub._
## Membuat SSH key
Ketika Anda ingin mengakses _private_ repositori Anda atau melakukan perubahan ke repositori GitHub Anda menggunakan SSH, Anda perlu menggunakan SSH _private key_ untuk proses autentikasi. Maka dari itu, buat SSH key pair menggunakan perintah berikut:
@ -105,7 +118,7 @@ Setelah memiliki _SSH key pair_ dan _SSH config file_ dikonfigurasi, saatnya men
1. Masuk ke __"Settings"__ > __"SSH and GPG keys"__ > Klik tombol __"New SSH key"__.
2. Isi __"Title"__ dengan apapun yang mudah Anda ingat untuk mengidentifikasi _SSH key_ Anda.
3. Pada bagian __"Key type"__, pilih __"Authentication Key"__.
4. Terakhir kembali ke terminal dan _paste_ isi dari __SSH public key__ (pada contoh tutorial ini adaalah `~/.ssh/github_key.pub`) key _textarea_ __"Key"__. Setelah itu klik tombol __Add SSH key"__.
4. Terakhir kembali ke terminal dan _paste_ isi dari __SSH public key__ (pada contoh tutorial ini adalah `~/.ssh/github_key.pub`) key _textarea_ __"Key"__. Setelah itu klik tombol __Add SSH key"__.
![menambahkan SSH key baru ke akun GitHub](github-add-new-ssh-key.jpg#center)

View file

@ -0,0 +1,129 @@
---
title: "How To Use Git Using SSH Protocol For GitHub"
description: "How to access your GitHub repositories using SSH protocol. Starting from creating an SSH key pair to adding an SSH public key to your GitHub account."
# linkTitle:
date: 2023-10-26T08:23:15+07:00
lastmod:
draft: false
noindex: false
# comments: false
nav_weight: 1000
# nav_icon:
# vendor: bootstrap
# name: toggles
# color: '#e24d0e'
series:
# - Tutorial
categories:
- TIL
tags:
- Git
- GitHub
- SSH
images:
# menu:
# main:
# weight: 100
# params:
# icon:
# vendor: bs
# name: book
# color: '#e24d0e'
authors:
- jasmerah1966
- vie
---
This article may be useful for those of you who want to get started using **Git** and connecting to **GitHub** using the **SSH** protocol. The process starts from creating an **SSH key pair** to adding the **SSH public key** to your GitHub account.
<!--more-->
---
Git is one of the most popular and widely used _version controls_ by software developers around the world. Several _"Cloud" based version controls service build on top of Git_ such as [GitLab](https://about.gitlab.com/), [GitHub](https://github.com/), and [Codeberg](https://codeberg.org/) offer several unique features from each other. However, there is a feature that every provider definitely has, the feature is accessing and Git repositories using the SSH protocol.
The authentication process using the SSH protocol utilizes **SSH public and private keys** so you don't need to provide a _username_ or _personal access token_ every time you want to access or commit to your repository.
In this article, I want to share how to use the SSH protocol as an authentication method for a specific provider: GitHub. But before starting, make sure `git` and `ssh` are installed on your computer and of course you must have an account at GitHub.com.
## Global config
> _**Note**: If you have already setting up your Git global config, you can skip this step._
Run the following command to set your name and email when committing to Git repository:
```shell
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
```
Change `John Doe` and `johndoe@example.com` with your name and email address.
> _**Note**: Make sure the email address matches with the email address you use at GitHub.com._
## Creting SSH key
When you want to access your private repository or make changes to your GitHub repository using SSH, you need to use an SSH private key for the authentication process. Therefore, create an SSH key pair using the following command:
```shell
mkdir ~/.ssh && chmod 700 ~/.ssh
ssh-keygen -t ed25519 -f ~/.ssh/github_key -C "SSH key untuk github"
```
The command above will create a `.ssh` folder under your `$HOME` directory, change the directory permission, and put the generated __private key__ in `$HOME/.ssh/github_key` and the __public key__ in `$HOME/.ssh/github_key.pub`. Example of output from the `ssh-keygen` command above:
```plain
Generating public/private ed25519 key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/jasmerah1966/.ssh/github_key
Your public key has been saved in /home/jasmerah1966/.ssh/github_key.pub
The key fingerprint is:
SHA256:dPniZJhVTjmj2gOi5Q4we8gucBs6b+4fpPJ6J2xnj7Q SSH key untuk github
The key's randomart image is:
+--[ED25519 256]--+
| o. |
| =+ |
| . +..o |
| o o..=.. |
| . =.+ .S++ . |
|. *o+ . .+o. |
|o=.+oo .. |
|+oO.++. |
|.@=*E.. |
+----[SHA256]-----+
```
> _**Note**: You will be asked to enter a `passphrase` during the SSH key pair generation process above. It's up to you whether you want to fill or leave your SSH key passphrase empty. If you fill in a passphrase, you will be asked to provide the passphrase when you use the SSH key._
## Using SSH config file
Many tutorials out there use `ssh-agent` as their _SSH key manager_. However, I prefer the trick used by @ditatompel by taking advantage of [using the SSH Config File]({{< ref "/tutorials/automate-cyberpanel-git-push-without-git-manager/index.md#make-use-of-ssh-config-file" >}}) feature.
Add (or create if the file doesn't already exist) the following lines to the SSH config file in `~/.ssh/config`:
```plain
# ~/.ssh/config file
# ...
Host github.com
User git
PubkeyAuthentication yes
IdentityFile ~/.ssh/github_key
# ...
```
Make sure the `IdentityFile` refers to the SSH private key that you created before (example if you follow this article it is `~/.ssh/github_key`).
## Adding your SSH public key to your GitHub account
Once you have your SSH key pair and SSH config file configured, it's time to add your SSH **public key** to your GitHub account.
1. Go to __"Settings"__ > __"SSH and GPG keys"__ > click on __"New SSH key"__ button.
2. Fill __"Title"__ with anything that you can easily remember to identify your SSH key.
3. On __"Key type"__ options, choose __"Authentication Key"__.
4. Finally, go back to your terminal and _paste_ content of your __SSH public key__ (in this tutorial is `~/.ssh/github_key.pub`) to __"Key"__ _textarea_. Then submit by pressing __Add SSH key"__ button.
![Adding new SSH key to GitHub account](github-add-new-ssh-key.jpg#center)
The configuration process is complete and you can try connecting to GitHub with `ssh -T github.com` command from your terminal. You should receive a message that your connection to GitHub was successful: "**Hi jasmerah1966! You've successfully authenticated, but GitHub does not provide shell access**.".
Next: Read [How To Create Verified Sign Git Commit Using SSH or GPG Signature]({{< ref "/tutorials/how-to-create-verified-sign-git-commit/index.md" >}}).