title: 如何生成多个ssh并将hexo博客布置到github

6 篇文章 0 订阅

原文地址Seven’s Blog

生成新的公钥和密钥


生成新的公钥
$ ssh-keygen -t rsa -C "your-email-address"

注意这里不能一直按enter键,否则会覆盖原来我的ssh。
当出现下面的第一行时,要输入新的ssh的地址并且命名。如下就是将id_rsa_aaa保存在了root/.ssh/下,并命名为id_rsa_aaa。注意window目录下不是root,你要找到你相应的.ssh的地址。如/c/users/username/.ssh/

Enter file in which to save the key (/root/.ssh/id_rsa):/root/.ssh/id_rsa_aaa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa_aaa.

输入后就生成了一个新的ssh。


将公钥拷贝到github

这时候需要进入github的settings里面的ssh。并把生成的公钥复制到对应的栏目里。直接vi id_rsa_aaa.pub,就可以编辑复制。


加入ssh agent上

把该key加到ssh agent上。由于不是使用默认的.ssh/id_rsa,所以你需要显示告诉ssh agent你的新key的位置

$ ssh-add ~/.ssh/id_rsa_aaa

这时,你可能会报一个错:

Could not open a connection to your authentication agent 

此时先执行 eval ssh-agent(是~键上的那个)再执行 ssh-add ~/.ssh/id_rsa_aaa就可以成功。下面可解释原因。

SSH private-keys are usually stored encrypted on the computers they are stored on. A pass-phrase is used to decrypt them when they are to be used. Since most people use SSH public-private key-pairs to get around typing in passwords all the time, the ssh-agent daemon exists to store decrypted private-keys you plan on using in a given session. The thing most people get tripped up on when using ssh-agent is that what the program outputs, some borne or csh shell commands, needs to be run. It may look like ssh-agent has set some variables for you, but it has in fact done no such thing. If you call ssh-add without processing ssh-agent’s output, it will complain it is unable to open a connection to your authentication agent. The most straightforward way to run ssh-agent on the command line is as follows: eval ssh-agent. After doing this, calls to ssh-add should succeed without error.

可以通过下面的命令测试是否生成ssh成功:

//检测原来的github账号的ssh是否设置成功
ssh -T git@github.com
//检测新的ssh是否设置成功
ssh -T git@github_aaa.com

配置config文件

.ssh下面本来是没有config文件,因为默认你的电脑就只有一个github与本地关联。但由于此时有多个github和对应的ssh,所以必须要配置才能加以区分。进入$ vi .ssh/config。并加入下列内容。保存后退出。

# 加上以下内容
#default github
Host github.com
  HostName github.com
  IdentityFile ~/.ssh/id_rsa

Host github_aaa.com
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_aaa

如何使用

这样的话,你就可以通过使用github.com别名github_aaa来明确说你要是使用id_rsa_aaa的SSH key来连接github,即使用工作账号进行操作,如下:

#本地建库
$ git init
$ git commit -am "first commit' 
#push到github上去
$ git remote add origin git@github_aaa.com:xxxx/test.git
$ git push origin master

由于我是要把hexo博客部署到github上,所以方式有所不同,更改_config.yml文件:

deploy:
  type: git
  repository: git@github_aaa.com:zxqblog/zxqblog.github.io.git
  branch: master

如上,上面的@后面不是github.com而是我们刚刚起的别名,github_aaa.com。注意这里的type要写成git而不是默认的github,否则会报下面的错:

error deployer not found:github

这是由于hexo 更新到3.0之后,deploy的type 的github需要改成git。


部署hexo博客到github

首先新建一个仓库

如:zxqblog.github.io。最好是以这种形式命名。Github Pages的Repository名字是特定的,比如我Github账号是cnfeat,那么我Github Pages Repository名字就是cnfeat.github.io。


部署仓库

使用命令

hexo clean
hexo generate
hexo deploy

在部署的过程中你可能会出现以下的几个问题:
问题1 Error: spawn ENOENT 错误信息解决方案

解决方法就是在cmd下敲的命令无法实现,我们把命令在git shell下面敲打就可以实现了。或者配置环境变量如:C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\libexec\git-core,这样就解决了问题了。

问题2 页面一直显示 404 page 解决方案

在github部署完成之后,马上访问可能出现404错误,这是正常的,(最多)等待十分钟左右就可以访问了。如果还不行,那很可能是 github 发送给你的验证邮件你没有打开看,据多方反映,验证后就没问题了。或者是验证邮箱里会出现deploy false的现象,并告诉你部署不成功的原因。这时候你去检查文件,再查找原因即可。

问题3 Page build failed: Missing submodule的解决方案

这个问题我犯的真的很低级。因为以前都是通过阿里云来部署我的网站。以为github page部署hexo是一样的,于是就用先前的:git init,git add,git commit,git remote add,git push来做。

但后来知道github page部署hexo不需要这样,只需要上面的步骤配置好_config.yml文件即可。造成这个错误的原因有很多。但是我的错误的大概原因是git里面又有git。或者是git文件不正确(不一定理解正确。。。)。解决方法是重建仓库,查到以前有人用:

- Make a backup of the content locally
- Delete the repository from GitHub
- Delete the repository locally
- Recreate the repository, ensuring that you don't include the repository within the repository locally, which is what you did previously
- Push it to GitHub

这个方法解决了,其实就是重新建了仓库。简单的方法是把原来blog里的所有git全部删除,包括deploy_git。然后把github上的文件全部清空。只保留库名字。然后再deploy即可。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值