Linux

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

2020-01-13  本文已影响0人  FinalException

categories:


SSH 验证就是我们键入命令 hexo deploy 以后,当那些需要提交的内容显示完成过后会弹出的一个小窗口提示我们输入用户名、密码。此处我们设置ssh公钥,实现hexo deploy时免密登陆。

1. 生成 SSH 密钥

cd ~/.ssh

使用 ssh-keygen 生成密钥

ssh-keygen -t rsa -C "your_email@example.com"

后面的三次输入均可使用默认值,Enter回车跳过

密钥生成成功

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. 设置 Gitee 项目的 Deploy keys(Github项目类似)

接下来测试配置是否成功

ssh -T git@Gitee.com

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

The authenticity of host 'gitee.com (xx.xx.xx.xx)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
ECDSA key fingerprint is MD5:27:e5:d3:f7:2a:9e:eb:6c:93:cd:1f:c1:47:a3:54:b1.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'gitee.com,xx.xx.xx.xx' (ECDSA) to the list of known hosts.
Hi xxx! You've successfully authenticated, but GITEE.COM does not provide shell access.

3.修改博客Git远程提交地址

# 修改 https 协议为 ssh 协议(仓库的ssh地址)
git remote set-url origin git@gitee.com:xxx/xxx.git

4.修改hexo根目录下_config.yml中的远程仓库设置

# Deployment

## Docs: https://hexo.io/docs/deployment.html

deploy:
  type: git
  repo: git@gitee.com:xxx/xxx.git
  branch: master

最后部署到远程就可以了

注:如果使用的是码云作为远程仓库部署,还需要在对应仓库的服务中手动部署一下

然后就可以愉快的玩耍了

上一篇 下一篇

猜你喜欢

热点阅读