git 多賬戶配置導致的 Permission denied (publickey).

踩坑總結

網上關於git多賬戶配置的文章很多,但是其實有誤導,以如下配置來說吧:

# This is the account for author on github.com.
	Host github.com
	HostName github.com
	User user1
	IdentityFile ~/.ssh/id_rsa_github
	PreferredAuthentications publickey
# This is the account for author on gitee.com.
	Host gitee.com
	HostName gitee.com
	User user2
	IdentityFile ~/.ssh/id_rsa_gitee
	PreferredAuthentications publickey
# This is the account for author on git.d.com.
	Host git.d.com
	HostName git.d.com
	User user3
	IdentityFile ~/.ssh/id_ed25519_gitlab
	PreferredAuthentications publickey

這個是一個支持三個git站點的拉取推送配置,這裏面的Host其實就是git@Host內容,譬如[email protected][email protected] ,這個參數是最重要的,如果這個參數寫錯了,就可能導致如下的奇怪現象:

ssh -T [email protected] 是正常返回的,
git push 報錯,[email protected]: Permission denied (publickey).

這裏面的IdentityFile就是ssh公鑰生成的位置,這裏需要了解一下,windows10下可以使用斜槓和~,不需要使用 “C:\Users\Administrator\.ssh\公鑰” 這樣的轉義反斜杆寫法,但是也是可以用的。

官方解決方案

其實最靠譜還是官方文檔,裏面說的很是清楚,能少走很多彎路:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章