以下為最標準、最安全、最佳實務的 GitHub SSH 設定流程。設定完成後:
git clone/git push不需輸入密碼或 Token- 永久登入,不用每次驗證
- 適合 WSL、Linux、Mac、Windows 使用者
ssh-keygen -t ed25519 -C "your_email@example.com"這是一個「註解」(comment),通常放你的 GitHub Email,用來識別這把 key。
- 不影響登入機制
- 純粹是識別用途(讓你知道這把 key 是做什麼的)
- GitHub UI 上會顯示這段 comment
範例:
ed25519 AAAAC3Nz... your_email@example.com
一路按 Enter 即可,會產生兩個檔:
~/.ssh/id_ed25519 # 私鑰(不能分享)
~/.ssh/id_ed25519.pub # 公鑰(可以分享)
cat ~/.ssh/id_ed25519.pub複製整串內容。
GitHub → Settings → SSH and GPG keys → New SSH key
貼上剛剛複製的公鑰。
git clone git@github.com:USERNAME/REPO.gitgit clone https://github.com/USERNAME/REPO.giteval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519echo 'eval "$(ssh-agent -s)"' >> ~/.bashrc
echo 'ssh-add ~/.ssh/id_ed25519' >> ~/.bashrcssh -T git@github.com成功會看到:
Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
現在你所有 GitHub 動作都能:
- 不用密碼
- 不用 Token
- 更安全
- 更簡潔