# [git][Authentication] remote: Support for password authentication was removed。git push時授權認證問題
###### tags: `git` `Authentication`
## 錯誤訊息
- 背景
- ssh遠端連線server時,執行`git push`
- 錯誤訊息
```bash=
Username for 'https://github.com':
Password for 'https://<your_username>@github.com':
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/<your_username>/<your_repository>.git/'
```
## 錯誤原因
- 這個錯誤訊息顯示使用者嘗試透過 HTTPS 方式進行 Git push,但是身份驗證失敗。原因是 GitHub 在 2021 年 8 月 13 日已經移除了使用帳號密碼進行身份驗證的方式,改為推薦使用其他方式進行身份驗證。
- 請參考 https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls 了解目前推薦的身份驗證方式。
## 解決方案
為了解決這個問題,可以遵循 GitHub 的推薦方式進行身份驗證。以下是其中的兩種方式:
### 1. 透過 Personal Access Token 進行身份驗證
- [x] 測試成功
Personal Access Token 是一種替代帳號密碼進行身份驗證的方式,可讓使用者透過 HTTPS 方式使用 Git 指令,同時也可以在其他應用程式中使用。要建立 Personal Access Token,請參考下列步驟:


- 登入到您的 GitHub 帳戶
- 點擊右上角的個人頭像,選擇 Settings
- 在左側的選單中,選擇 Developer settings,然後選擇 Personal access tokens
- 點擊 Generate new token
- 為這個 Token 命名,然後勾選需要的權限
- 點擊 Generate token
- 複製這個 Token,並使用它來進行身份驗證
在使用 Personal Access Token 時,可以在 Git push 指令中使用它來進行身份驗證,例如:
```bash=
git push --set-upstream origin <your_repository>
Username for 'https://github.com': <your_username>
Password for 'https://<your_username>@github.com': <your_personal_access_token>
```
成功的話就會跳出下列的訊息

### 2. 透過 SSH 金鑰進行身份驗證
- [ ] 待測試
另一種替代帳號密碼進行身份驗證的方式是使用 SSH 金鑰。這種方式需要在使用 Git 指令之前設定 SSH 金鑰,然後在 GitHub 帳戶中添加公鑰。要使用 SSH 金鑰進行身份驗證,請參考以下步驟:
- 創建 SSH 金鑰。可以在終端機中使用 ssh-keygen 指令,或者使用其他 SSH 金鑰管理工具。
- 將 SSH 公鑰添加到您的 GitHub 帳戶。在 GitHub 帳戶的設置中,選擇 SSH and GPG keys,然後點擊 New SSH key。將公鑰複製到這裡並保存。
- 在 Git push 指令中使用 SSH 金鑰進行身份驗證,例如:
```bash=
git push --set
```