---
# System prepended metadata

title: Git and GitHub config
tags: [GitHub, Git, 邁向全端修煉之路]

---

# Git and GitHub config
###### tags: `邁向全端修煉之路`, `Git` `GitHub`

## Config
`$ git config --global user.name <user-name>`
`$ git config --global user.email <user-email>`

## Public and Private Keys
1. GitHub 從2021年開始不建議使用密碼驗證(HTTP)，建議用SSH連線方式操作Git repo
2. 公私鑰觀念
3. Create SSH Keys
    * `$ ssh-keygen -t ed25519 -C "your email"`: generate public and private key to `~/.ssh` folder.
4. Add SSH Key to ssh-agent:
    * Make sure ssh-agent is running in the background.
        ```bash
        $ eval `ssh-agent`
        ```
        (這邊有些人的寫法是`eval "$(ssh-agent) -s"`，但會報錯)
        ![](https://i.imgur.com/OKcxqAl.png)

    * Add your SSH private key to the ssh-agent.
        ```bash
        $ ssh-add ~/.ssh/ed_25519
        ```
5. Add SSH Key to GitHub Account
* `$ cat ~/.ssh/ed_25519.pub` and copy the output and paste into GitHub.

6. Test SSH connection with a Repo

### Reference 
* [How to Generate SSH Keys for GitHub](https://kinsta.com/blog/generate-ssh-key/)
* [Official Documentation](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)
* [設定 Github SSH 金鑰 feat. Github SSH、HTTPS 的差異](https://ithelp.ithome.com.tw/articles/10205988)