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

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