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]
此時,應該在預設路徑下,生成了兩個檔案,一個是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:
7、將SSH金鑰新增到SSH-Agent,其中hexo_rsa是生成SSH設定的名稱
ssh-ADD~ /.ssh/hexo_rsa
8、開啟hexo_rsa.pub檔案,複製其內容,然後開啟Github賬戶,按圖片步驟設定,最後將複製內容放置Key內容中,設定title,點選新增即可。
驗證SSH連結是否成功:
輸入命令:
ssh -T [email protected]
你將會看到
輸入Yes既可以