Github 生成新的SSH密鑰並添加至SSH-Agent

問題:hexo d 時出現錯誤 Error: ERROR: Permission to

remote: Permission to huweihuang/hexo-theme-huweihuang.git denied to wanghaijuan.
fatal: unable to access 'https://github.com/huweihuang/hexo-theme-huweihuang/': The requested URL returned error: 403
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html

Error: remote: Permission to huweihuang/hexo-theme-huweihuang.git denied to wanghaijuan.
fatal: unable to access 'https://github.com/huweihuang/hexo-theme-huweihuang/': The requested URL returned error: 403

    at ChildProcess.<anonymous> (D:\project\blog\hexo-huweihuang\node_modules\hexo-deployer-git\node_modules\hexo-util\lib\spawn.js:37:17)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at ChildProcess.cp.emit (D:\project\blog\hexo-huweihuang\node_modules\cross-spawn-async\lib\enoent.js:37:29)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)

原因:huweihuang/hexo-theme-huweihuang.git 拒絕接受 wanghaijuan。 說明當前有兩個github賬號,可以更新博客, 新的github賬號沒有配置好。

解決辦法:在Github生成新的SSH密鑰

配置步驟:

一、生成新的SSH密鑰

1、打開Git Bash。

2、 進入.ssh 根目錄下。

cd ~/.ssh

3、輸入GitHub電子郵件地址,其中[email protected]是您關聯的GitHub郵箱。

ssh-keygen -t rsa -b 4096 -C "[email protected]"

4、輸入保存的密鑰文件並接受默認文件地址,按Enter鍵

// 用提供的電子郵件作爲標籤創建一個新的ssh密鑰。(無需操作)
Generating public/private rsa key pair. 
// 輸入名稱並按Enter鍵,其中hexo_rsa可自行設置
Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):hexo_rsa

5、輸入安全密碼,沒有則爲空,按Enter鍵進行下一步

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

clipboard.png

此時,應該在默認路徑下,生成了兩個文件,一個是hexo_rsa,另一個是hexo_rsa.pub;

二、將SSH密鑰添加到SSH-Agent

在將新的SSH密鑰添加到SSH-Agent管理密鑰之前,您應該檢查現有的SSH密鑰。

ls -al ~/ .ssh

看下返回的結果中是否已經存在了.pub結尾的文件,如果沒有需要生成一個新的,如果存在了,直接看將SSH密鑰配置到Github賬戶;

6、啓動ssh-agent,執行命令:

eval $(ssh-agent -s)

返回agent的Pid:

clipboard.png

7、將SSH密鑰添加到SSH-Agent,其中hexo_rsa是生成SSH設置的名稱

ssh-ADD~ /.ssh/hexo_rsa

8、打開hexo_rsa.pub文件,複製其內容,然後打開Github賬戶,按圖片步驟設置,最後將複製內容放置Key內容中,設置title,點擊添加即可。

clipboard.png

驗證SSH鏈接是否成功:
輸入命令:

ssh -T [email protected]

你將會看到

clipboard.png

輸入Yes既可以

clipboard.png

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