2021年8月15日 星期日

Git gui 使用有 passphrases 的 ssh key 連到 GitHub

因為 2021/08/13 後,github 不給用 https 加密碼方式連線,

只能用 ssh key 的方式。

但是照著步驟一直失敗

Pushing to ssh://github.com/myname/project.git
myname@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


照著新增 ssh key

https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

打開 git gui 複製使用的 public key


到這頁面按 New SSH key 加入 public key

https://github.com/settings/keys


一開始打開 project/.git/config

直接把 

url = htts://github.com/myname/project.git

改成

url = ssh://github.com/myname/project.git

都顯示失敗,

使用下列測試連線又顯示可以

#ssh -T -i ~/.ssh/private_key git@github.com



後來到 github 的 project 頁面看 ssh 的連線內容

改成git@github.com開頭就可以正常連線,

有 passphrases 也會在第一次時出現對話框。


參考資料:

Generating a new SSH key and adding it to the ssh-agent

https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

Working with SSH key passphrases

https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/working-with-ssh-key-passphrases

Git 踩坑紀錄(二)git clone with SSH keys 或 HTTPS 設定步驟

https://tsengbatty.medium.com/git-%E8%B8%A9%E5%9D%91%E7%B4%80%E9%8C%84-%E4%BA%8C-git-clone-with-ssh-keys-%E6%88%96-https-%E8%A8%AD%E5%AE%9A%E6%AD%A5%E9%A9%9F-bdb721bd7cf2

沒有留言:

張貼留言