让git和HEXO记住你的用户名和密码,反正咱也写不出啥值钱的代码

感谢这位大哥的文章
看完之后应该就明白了吧。我重述一下:
1.打开terminal,使用 ssh-keygen 生成密钥

$ ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key using the provided email
Generating public/private rsa key pair.
Enter file in which to save the key (/home/you/.ssh/id_rsa)

使用默认的文件名直接enter,接下来显示如下

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
按提示输入密码即可(简化流程的话在键入命令 ssh-keygen -t rsa -C “your_email@example.com“ 以后的三次提示输入都可以直接回车跳过)。
密钥生成成功

Your identification has been saved in /home/you/.ssh/id_rsa.
Your public key has been saved in /home/you/.ssh/id_rsa.pub.
The key fingerprint is:
…………………此处是密钥内容…………………… your_email@example.com

2.可以选择是在用户设置中添加密钥(Settings –> SSH GPG keys)还是单个项目中添加密钥,在这里我就在我们的博客项目中添加密钥,此处以我的博客为例。
在 chengjianhua.github.io 的首页菜单栏中点击 Settings –> Deploy keys –> Add deploy key,然后将生成的 id_rsa.pub 中的内容全选复制到 key 输入框中,然后点击 Add key 完成添加公钥。

接下来测试配置是否成功

$ ssh -T git@github.com

如果出现以下内容即表示配置完成并且成功!

Hi username! You've successfully authenticated, but GitHub does not
provide shell access.

这是大哥说的,我测试了,没反应,不知道是不是被屏蔽了,不然我们这些屌丝乱ssh,anyway反正也不影响使用。
3.
这时我想到了 hexo 的配置文件 _config.yml 中的 deploy 属性。

deploy:
type: git
repo: git@github.com:chengjianhua/chengjianhua.github.io.git
branch: master

我将其中的 repo修改成了git@github.com:chengjianhua/chengjianhua.github.io.git,这个时候我再尝试了 $ hexo deploy 果然成功了,就不用输入密码了!

#亲测有效,希望能帮到使用HEXO的同学们

加载评论框需要翻墙