Hexo deploy 时免输用户名密码


首先关于Hexo-admin

使用了一位大佬修改后的Hexo-admin,解决了windows系统插入图片失败问题解决,通过修改源码完美解决,hexo-admin汉化,以及添加按文章存储图片功能(方便管理)

回归正题

  • 设置 SSH 使用 hexo deploy 时免输用户名密码

生成 SSH 密钥

右键鼠标任意位置打开 Git Bash Here,然后输入以下命令

cd ~/.ssh

使用 ssh-keygen 生成密钥

ssh-keygen -t rsa -C "your_email@example.com"
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

设置 Github 项目的 Deploy keys

以我的博客为例,在 izyq.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.

修改hexo根目录的配置文件

修改_config.yml 中的deploy属性,将repo改为
git@github.com:USERNAME/REPOSITORY.git
如下

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

这个时候再尝试了 $ hexo deploy 就成功了,就不用老是输入密码了!


文章作者: 周master
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 周master !
  目录