Hexo d一台电脑deploy到两个不同的github帐号

如何用一台电脑部署两个不同的github帐号

一、 git配置

  1. 进入 .ssh 目录:C:\Users\yourusername\ .ssh

  2. 右键 git bush here

  3. 新建密钥:新邮箱

    1
    ssh-keygen -t rsa -C youremail
  4. 输入新密钥的名字回车、回车、回车:例如:newkey

    1
    Enter file in which to save the key (/c/Users/you/.ssh/id_rsa):newkey
  5. 新建配置文件:

    1
    touch config
  6. 用文本编辑器编辑文件 config:前缀随意(可以设置成你新github的用户名),记住就行;第二个配置,newkey是刚刚新建密钥的名字

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    # 第一个:
    Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa
    # 第二个:
    Host 前缀.github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/newkey
  7. 添加新密钥:依次执行下列命令:-D是清除密钥,然后添加两密钥进去,默认的id_rsa是第一个帐号的密钥,newkey是刚才新建的密钥。

    1
    2
    3
    4
    ssh-agent bash
    ssh-add -D
    ssh-add id_rsa
    ssh-add newkey

二、 github配置:

  1. 打开文件夹,找到newkey.pub,复制内容
  2. 打开github > Your repositories > settings > Deploy keys > Add deploy key
  3. title随意,把密钥的粘贴进去
  4. 记得勾选:□ Allow write access

三、 配置第二个hexo的config文件:不知道前缀是什么的话,请看:一、6

这里要注意的是repo的格式,git@前缀.github.com:(注意冒号)github用户名/github用户名.github.io.git

1
2
3
4
deploy:
type: git
repository: git@前缀.github.com:github用户名/github用户名.github.io.git
branch: master

四、 上传;若是不行,再操作一遍

  1. 进入新hexo根目录
  2. 右键 git bash here
  3. 执行下列代码:
    1
    2
    hexo clean
    heox g -d
-------------本文结束 感谢您的阅读-------------
转载别忘了注明出处哈
🍭🍭🍭😜
0%